Questions tagged [execfile]

execfile is a Python 2.x. built-in function that executes Python scripts from files.

88 questions
0
votes
2 answers

execfile with automatic relative path

I need to be able to call python scripts via execfile() from outside the working directory without specifying the relative file path each time through the interpreter. instead of: execfile("..\\UserScripts\\HelloWorld.py") I need to…
john.dennis
  • 56
  • 2
  • 7
0
votes
1 answer

Python: NameError: global name 'x' is not defined

In my main() function I open a config file: cfg = {} execfile("config.conf", cfg) config.conf looks like this: x = 10 Later on, I use cfg[x], which gives me NameError: global name 'x' is not defined. I took the example from here, how I use it,…
PMint
  • 246
  • 2
  • 13
0
votes
1 answer

Timeout on an execfile call function for windows? (Signal Alternative?)

Pretty much as the title says, I'm trying to run some execfile calls but I am looking for a timeout option so that if my called script takes over ten seconds to run then it will kill the called script and continue... The signal library/package is…
Ryflex
  • 5,559
  • 25
  • 79
  • 148
0
votes
2 answers

Executing a script within a script but continuing on error(s) and saving them to file

If I was to have the following bit of code: try: execfile("script.py") except ## unsure what exception goes here... continue: try: execfile("other.py") except ## unsure what exception goes here... continue: How do I catch all…
Ryflex
  • 5,559
  • 25
  • 79
  • 148
0
votes
2 answers

Python metaclass, execfile, inspect, globals(), namespace

When the following script is run directly, it operates as anticipated: import inspect __module__ = "__main__" __file__ = "classes.py" test_str = "test" class met(type): def __init__(cls, name, bases, dct): setattr(cls, "source",…
dilbert
  • 3,008
  • 1
  • 25
  • 34
0
votes
1 answer

jython error "Exception in thread "AWT-EventQueue-0""

i tried to run a python script using Jython, from javax.swing import JButton,JFrame def action(): execfile(r"E:\stack.py") frame = JFrame("window") button = JButton("button", actionPerformed = action) frame.add(button) frame.show() But it's…
user19911303
  • 449
  • 2
  • 9
  • 34
0
votes
2 answers

Unknown url handler type, execfile is not defined

Trying to implement the tutorial 'Hello world'. When I select Python 3.1 nothing happens and the log says that execfile(script_path, globals_) is not defined. When I use python 2.7 the terminal window opens but nothing happens for a while and then…
0
votes
1 answer

execute python script with argparse inside python script

I got two different python script, the first one is using argparse to get some additional argument (I will call it arg.py) and the second one is my main script (main.py). I want to call arg.py inside main.py but I don't know how to do so. I take a…
0
votes
2 answers

Iterate a Python script over files, with wildcard expansion, and passing through args

I have some scripts which do some processing on a file. Typically they accept the file as their first command-line argument, and other arguments after that. I want to write a master script which accepts the name of the script to run, a wildcard…
bavaza
  • 10,319
  • 10
  • 64
  • 103
-1
votes
1 answer

Global name is not defined when running script with closures with execfile

I am trying to run script2 from script1 with execfile and script2 contains closures: script1.py MyVar1 = 'value1' def fun1(): print(MyVar1) def fun2(): execfile('script2.py') fun1() fun2() script2.py MyVar2 = 'value2' def…
Dims
  • 47,675
  • 117
  • 331
  • 600
-1
votes
2 answers

Initialize only once

I've got a couple of scripts (named one.py and two.py) circularly calling each other using execfile. The one.py (which is the one to start) has some code (initialize) that I would like to execute only once. I would like to continue using execfile…
user1530405
  • 447
  • 1
  • 8
  • 16
-2
votes
1 answer

Alternative to the python "Execfile" in JAVA?

I was wondering if there where any same command as execfile ( from Python ) to java?
hyspo
  • 29
  • 5
-3
votes
2 answers

Making an Exe file with pyinstaller

If suppose I use the function execfile in my python script and then I use pyinstaller to convert that python script into an executable file then will that executable file work?What pyisntaller does is look for import statement and then include those…
Akshay
  • 463
  • 6
  • 15
1 2 3 4 5
6