Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #10160

Re: run a script getting 4 arguments from another script

Date 2011-07-23 02:19 +0200
From Thomas Jollans <t@jollybox.de>
Subject Re: run a script getting 4 arguments from another script
References <38a06421-c05d-42d0-b0e5-9bd85ccf3c0b@12g2000yqr.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.1395.1311380339.1164.python-list@python.org> (permalink)

Show all headers | View raw


On 23/07/11 00:46, souleymane yo wrote:
> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

run a script getting 4 arguments from another script souleymane yo <souleymaneyo@gmail.com> - 2011-07-22 15:46 -0700
  Re: run a script getting 4 arguments from another script Thomas Jollans <t@jollybox.de> - 2011-07-23 02:19 +0200

csiph-web