run a script getting 4 arguments from another script

S

souleymane yo

my initial file name is SpO2Sweep.loops.py
In the new file I write this code to run the first one.

[code:]
import SpO2Sweep.loops.py
SpO2Sweep.loops.py.run("com1","0","30","0.0001")


and It looks like the arguments are not passed to the first file. can
someone help me?
 
T

Thomas Jollans

my initial file name is SpO2Sweep.loops.py
In the new file I write this code to run the first one.

[code:]
import SpO2Sweep.loops.py
SpO2Sweep.loops.py.run("com1","0","30","0.0001")


and It looks like the arguments are not passed to the first file. can
someone help me?

tl;dr:

rename your file to a valid Python identifier, without periods, for
example "loops.py". Then, you can use "import loops" (note: no .py), and
loops.run(...)

tl:

When you say "import SpO2Sweep.loops.py", Python interpets the '.' as a
separator between nested package/module names, much like your operating
system interpets '/' (or perhaps '\') as a separator between
directory/file names. Python thus looks for the module or package "py"
within the package "loops" within the package "SpO2Sweep". For this to
work, you'd need the following directory layout:

../
SpO2Sweep/
__init__.py
loop/
__init__.py
py.py

Note: A file named __init__.py turns a plain directory into a package
that Python recognises.

What you actually have is this:

../
SpO2Sweep.loop.py

(That won't work)

Since Python treats periods specially, and names in Python cannot
contain periods (the special meaning of '.' trumps), you can never
import a file with that name.

- Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top