Re: Importing module from another subdirectory

2019-04-25 Thread Rich Shepard
On Thu, 25 Apr 2019, dieter wrote: The means that "test_act_de.py" has not extended "sys.path" appropriately. Dieter, That's what I thought. When Python starts a script ("gui/test_act_de.py" in your case), it automatically extends "sys.path" with the folder containing the script ("gui" in y

Re: Importing module from another subdirectory

2019-04-24 Thread dieter
Rich Shepard writes: >> bustrac/ >>README.rst >>bustrac.py* >>controller/ >>classes/ > model.py >>scripts/ >>gui/ > test_act_de.py > > test_act_de.py tries to import model.py from the classes package: > from classes import model as m > > Running in bustrac

Re: Importing module from another subdirectory

2019-04-24 Thread Rich Shepard
On Wed, 24 Apr 2019, Rich Shepard wrote: The current project's directory structure is: I changed package names so there are no duplicate names for packages and modules. bustrac/ README.rst bustrac.py* controller/ classes/ model.py scripts/ gui/ test_act

Re: Importing module from another subdirectory

2019-04-24 Thread Rich Shepard
On Wed, 24 Apr 2019, Rich Shepard wrote: If I correctly understand the process, in bustrac.py I'll add import sys.path sys.path.append(controller, model, scripts, views) Never mind. I've installed virtualenv and will work within it. Regards, Rich -- https://mail.python.org/mailman/listinfo/p

Re: Importing module from another subdirectory

2019-04-24 Thread Rich Shepard
On Wed, 24 Apr 2019, dieter wrote: With a "virtualenv", there is usually no need to tweak "sys.path" -- you simply install everything your project needs into the "virtualenv". Dieter, Okay. I just upgraded pip to 19.1 for python3 and virtualenv to version 16.5.0. Now I'll learn how to use it

Re: Importing module from another subdirectory

2019-04-24 Thread Rich Shepard
On Wed, 24 Apr 2019, dieter wrote: "sys.path" tweaks are typically employed with a "central" Python installation, to have it look at non-standard places for module/packages under specific circumstances. Almost all python packages installed here are built using the SlackBuilds.org scripts (I ru

Re: Importing module from another subdirectory

2019-04-23 Thread dieter
Rich Shepard writes: > On Tue, 23 Apr 2019, dieter wrote: > ... > One project is for my own use and I understand now that a virtualenv with > its own sys.path appendices would work. Those are two separate approaches: With a "virtualenv", there is usually no need to tweak "sys.path" -- you simply

Re: Importing module from another subdirectory

2019-04-23 Thread Rich Shepard
On Tue, 23 Apr 2019, dieter wrote: I use "virtualenv" (for "VIRTUAL ENVironmet") to separate projects. Dieter, I know about virtualenv and tried using them. Found conflicting information and didn't know if I really needed them. I'll re-learn how to activate and use them. One project is for m

Re: Importing module from another subdirectory

2019-04-22 Thread dieter
Rich Shepard writes: > On Thu, 18 Apr 2019, dieter wrote: > ... >> 2. extend "sys.path" in your scripts to contain the "bustrac" folder >> (before you try to import infrastructure modules/packages) > > I read the docs for sys and site and have insufficient experience with them > to know how best t

Re: Importing module from another subdirectory

2019-04-22 Thread Rich Shepard
On Thu, 18 Apr 2019, dieter wrote: I see two options for you: 1. put your scripts directly into "bustrac" (rather than a subdirectory) There are too many files; the directory is very cluttered. 2. extend "sys.path" in your scripts to contain the "bustrac" folder (before you try to import in

Re: Importing module from another subdirectory

2019-04-18 Thread Rich Shepard
On Thu, 18 Apr 2019, dieter wrote: Python knows about 2 kinds of "regular" imports: absolute ones and relative ones. "Absolute" imports are guided by "sys.path" -- in the simple case, a sequence of folders containing modules and/or pacakges. Relative imports are guided in a similar way by the cu

Re: Importing module from another subdirectory

2019-04-18 Thread Rich Shepard
On Wed, 17 Apr 2019, Sayth Renshaw wrote: Apologies I don't know the answer but went looking. This guide should answer the question. Didn't know it was so difficult to be honest. https://chrisyeh96.github.io/2017/08/08/definitive-guide-python-imports.html#example-directory-structure Then there

Re: Importing module from another subdirectory

2019-04-17 Thread dieter
Rich Shepard writes: > What is the proper syntax to import the model class in the model/ > subdirectory into a tkinter view module, e.g., activities.py? The syntax, > 'import model as m' fails because it is not in the same subdirectory as the > importing module. > > T

Re: Importing module from another subdirectory

2019-04-17 Thread Sayth Renshaw
On Thursday, 18 April 2019 06:59:43 UTC+10, Rich Shepard wrote: > What is the proper syntax to import the model class in the model/ > subdirectory into a tkinter view module, e.g., activities.py? The syntax, > 'import model as m' fails because it is not in the same subdirectory

Importing module from another subdirectory

2019-04-17 Thread Rich Shepard
What is the proper syntax to import the model class in the model/ subdirectory into a tkinter view module, e.g., activities.py? The syntax, 'import model as m' fails because it is not in the same subdirectory as the importing module. The program directory tree is: bustrac/

Re: Setting PYTHONPATH does not allow importing module

2015-03-04 Thread cl
fa...@vt.edu wrote: > I have the following directory /home/me/projects/modulename. > > I update PYTHONPATH using the following command: > export PYTHONPATH=$PYTHONPATH:/home/me/projects/modulename > > It seems to have been added: > [me@machine ~]$ python -c "import sys; print(sys.path)" > ['',...

Re: Setting PYTHONPATH does not allow importing module

2015-03-03 Thread Zachary Ware
On Tue, Mar 3, 2015 at 9:47 PM, wrote: > On Tuesday, March 3, 2015 at 10:43:27 PM UTC-5, Zachary Ware wrote: >> Try adding /home/me/projects to PYTHONPATH instead of >> /home/me/projects/modulename. > > Ah, that worked! Yes, I see that the modulename must be visible. Thanks a lot! No problem, gl

Re: Setting PYTHONPATH does not allow importing module

2015-03-03 Thread faruk
On Tuesday, March 3, 2015 at 10:43:27 PM UTC-5, Zachary Ware wrote: > On Tue, Mar 3, 2015 at 9:25 PM, wrote: > > I have the following directory /home/me/projects/modulename. > > > > I update PYTHONPATH using the following command: > > export PYTHONPATH=$PYTHONPATH:/home/me/projects/modulename > >

Re: Setting PYTHONPATH does not allow importing module

2015-03-03 Thread faruk
On Tuesday, March 3, 2015 at 10:37:54 PM UTC-5, liuerfire Wang wrote: > Is there a file named __init__.py in the modulename dir? > > > > > > > > > Best regards > > > > > > On Wed, Mar 4, 2015 at 11:25 AM, wrote: > I have the following directory /home/me/projects/modulename. > > >

Re: Setting PYTHONPATH does not allow importing module

2015-03-03 Thread faruk
On Tuesday, March 3, 2015 at 10:37:54 PM UTC-5, liuerfire Wang wrote: > Is there a file named __init__.py in the modulename dir? > > > > > > > > > Best regards > > > > > > On Wed, Mar 4, 2015 at 11:25 AM, wrote: > I have the following directory /home/me/projects/modulename. > > >

Re: Setting PYTHONPATH does not allow importing module

2015-03-03 Thread Zachary Ware
On Tue, Mar 3, 2015 at 9:25 PM, wrote: > I have the following directory /home/me/projects/modulename. > > I update PYTHONPATH using the following command: > export PYTHONPATH=$PYTHONPATH:/home/me/projects/modulename > > It seems to have been added: > [me@machine ~]$ python -c "import sys; print(s

Re: Setting PYTHONPATH does not allow importing module

2015-03-03 Thread liuerfire Wang
Is there a file named __init__.py in the modulename dir? Best regards On Wed, Mar 4, 2015 at 11:25 AM, wrote: > I have the following directory /home/me/projects/modulename. > > I update PYTHONPATH using the following command: > export PYTHONPATH=$PYTHONPATH:/home/me/projects/modulename > > It

Setting PYTHONPATH does not allow importing module

2015-03-03 Thread faruk
I have the following directory /home/me/projects/modulename. I update PYTHONPATH using the following command: export PYTHONPATH=$PYTHONPATH:/home/me/projects/modulename It seems to have been added: [me@machine ~]$ python -c "import sys; print(sys.path)" ['',... '/home/me', '/home/me/projects/modu

Re: importing module versus using function?

2012-01-31 Thread Robert Kern
On 1/31/12 3:08 PM, gujax wrote: Hi, I am confused on this quite bad!! If I have this typed in interactive python: import numpy def dummy(): y=numpy.arange(1,2,0.1) return y and then s = dummy() s array[1. , 1.1, 1.2] it works. But if I have a module called example.p

importing module versus using function?

2012-01-31 Thread gujax
Hi, I am confused on this quite bad!! If I have this typed in interactive python: >>import numpy >>def dummy(): y=numpy.arange(1,2,0.1) return y and then >>s = dummy() >>s >>array[1. , 1.1, 1.2] it works. But if I have a module called example.py, whose code is def dummy():

Re: importing module

2010-09-09 Thread Peter Otten
Holzwarth, Dominique (Berne Branch) wrote: > Hi all > > Lets assume I have the following structure of directories and python > modules: > > Root-dir > |_dir1 > |_ script1.py > |_dir2 > |_ script2.py > |_sudir2 > |_ script3.py > > Is it possible to import script1 into script2 and scri

importing module

2010-09-09 Thread Holzwarth, Dominique (Berne Branch)
Hi all Lets assume I have the following structure of directories and python modules: Root-dir |_dir1 |_ script1.py |_dir2 |_ script2.py |_sudir2 |_ script3.py Is it possible to import script1 into script2 and script3? Or do have to put script1.py into the Lib\site-packages folder of

Re: importing module-performance

2009-02-02 Thread S.Selvam Siva
On Mon, Feb 2, 2009 at 3:11 PM, Chris Rebert wrote: > On Mon, Feb 2, 2009 at 1:29 AM, S.Selvam Siva > wrote: > > Hi all, > > I have a small query, > > Consider there is a task A which i want to perform. > > > > To perform it ,i have two option. > > 1)Writing a small piece of code(approx. 50 line

Re: importing module-performance

2009-02-02 Thread Chris Rebert
On Mon, Feb 2, 2009 at 1:29 AM, S.Selvam Siva wrote: > Hi all, > I have a small query, > Consider there is a task A which i want to perform. > > To perform it ,i have two option. > 1)Writing a small piece of code(approx. 50 lines) as efficient as possible. > 2)import a suitable module to perform t

importing module-performance

2009-02-02 Thread S.Selvam Siva
Hi all, I have a small query, Consider there is a task A which i want to perform. To perform it ,i have two option. 1)Writing a small piece of code(approx. 50 lines) as efficient as possible. 2)import a suitable module to perform task A. I am eager to know,which method will produce best performa

Trouble importing module using swig and python

2008-10-10 Thread Basha J P M
-importing-module-using-swig-and-python-tp19930052p19930052.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list

Re: Importing module with name given as a variable

2008-08-30 Thread Bruno Desthuilliers
Sean Davis a écrit : What is the "best practice" for importing an arbitrary module given that the name is stored in a variable? The context is a simple web application with URL dispatching to a module and function. I know of __import__(), the imp module, and exec. For each of these, is there a

Re: Importing module with name given as a variable

2008-08-30 Thread Wojtek Walczak
On Sat, 30 Aug 2008 11:02:03 -0700 (PDT), Sean Davis wrote: > What is the "best practice" for importing an arbitrary module given > that the name is stored in a variable? The context is a simple web > application with URL dispatching to a module and function. I know of > __import__(), the imp mod

Importing module with name given as a variable

2008-08-30 Thread Sean Davis
What is the "best practice" for importing an arbitrary module given that the name is stored in a variable? The context is a simple web application with URL dispatching to a module and function. I know of __import__(), the imp module, and exec. For each of these, is there a way to make them work

Re: Importing module PIL vs beautifulSoup.

2008-06-18 Thread bsagert
On Jun 18, 10:18 am, Duncan Booth <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > I downloaded BeautifulSoup.py from > >http://www.crummy.com/software/BeautifulSoup/and being a n00bie, I > > just placed it in my Windows c:\python25\lib\ file. When I type > > "import beautifulsoup" from th

Re: Importing module PIL vs beautifulSoup.

2008-06-18 Thread Duncan Booth
[EMAIL PROTECTED] wrote: > I downloaded BeautifulSoup.py from > http://www.crummy.com/software/BeautifulSoup/ and being a n00bie, I > just placed it in my Windows c:\python25\lib\ file. When I type > "import beautifulsoup" from the interactive prompt it works like a > charm. This seemed too easy i

Importing module PIL vs beautifulSoup.

2008-06-18 Thread bsagert
I downloaded BeautifulSoup.py from http://www.crummy.com/software/BeautifulSoup/ and being a n00bie, I just placed it in my Windows c:\python25\lib\ file. When I type "import beautifulsoup" from the interactive prompt it works like a charm. This seemed too easy in retrospect. Then I downloaded the

Re: importing module conflict

2008-01-10 Thread Matias Surdi
Ben Finney escribió: > Matias Surdi <[EMAIL PROTECTED]> writes: > >> Suppose I've a module named "urllib" and from it I need to import >> the urllib module from the python standart library. > > What you want is the "absolute import" behaviour, described in PEP 328 > http://www.python.org/peps/pep

Re: importing module conflict

2008-01-10 Thread Ben Finney
Matias Surdi <[EMAIL PROTECTED]> writes: > Suppose I've a module named "urllib" and from it I need to import > the urllib module from the python standart library. What you want is the "absolute import" behaviour, described in PEP 328 http://www.python.org/peps/pep-0328.html> and implemented in Py

Re: importing module conflict

2008-01-10 Thread Bruno Desthuilliers
Matias Surdi a écrit : > Hi, > > Suppose I've a module named "urllib" and from it I need to import the > urllib module from the python standart library. > > ¿how can I do this? > > The problem I found is that when I do: > > > import urrlib > > The imported module is itself, and not the one f

importing module conflict

2008-01-10 Thread Matias Surdi
Hi, Suppose I've a module named "urllib" and from it I need to import the urllib module from the python standart library. ¿how can I do this? The problem I found is that when I do: import urrlib The imported module is itself, and not the one from the stdlib. Any idea? Thanks a lot. -- ht

Re: Importing Module To Use Variables In A Second Module

2007-09-28 Thread Calvin Spealman
Most problems like this are caused by trying to access the attributes of the module before that module is fully executed, and thus before they are defined. For example, if you have A.py: import B data = "TEST" And B.py: import A print A.data Now, if you run A,py, it will import B before

Re: Importing Module To Use Variables In A Second Module

2007-09-27 Thread Steve Holden
[EMAIL PROTECTED] wrote: > On 2007-09-27, Steve Holden <[EMAIL PROTECTED]> wrote: > >> Self-evidently you are *not* creating the variables you think you are in >> the variablePage module. Have you tried an interactive test? Try this at >> the interpreter prompt: >> > import variablePage >

Re: Importing Module To Use Variables In A Second Module

2007-09-27 Thread rshepard
On 2007-09-27, Steve Holden <[EMAIL PROTECTED]> wrote: > Self-evidently you are *not* creating the variables you think you are in > the variablePage module. Have you tried an interactive test? Try this at > the interpreter prompt: > > >>> import variablePage > >>> dir(variablePage) > > and you wil

Re: Importing Module To Use Variables In A Second Module

2007-09-27 Thread Steve Holden
[EMAIL PROTECTED] wrote: > I'm stymied by what should be a simple Python task: accessing the value of > a variable assigned in one module from within a second module. I wonder if > someone here can help clarify my thinking. I've re-read Chapter 16 (Module > Basics) in Lutz and Ascher's "Learning

Importing Module To Use Variables In A Second Module

2007-09-27 Thread rshepard
I'm stymied by what should be a simple Python task: accessing the value of a variable assigned in one module from within a second module. I wonder if someone here can help clarify my thinking. I've re-read Chapter 16 (Module Basics) in Lutz and Ascher's "Learning Python" but it's not working for

Re: doubt with importing module, given module name

2007-04-13 Thread Pradnyesh Sawant
> module_name = "module" > mod = __import__(module_name) > class_name = module_name.capitalize() > cls = getattr(mod, class_name) > inst = cls() > Worked like a magic charm :) Also helped me understand the concept of getattr :D Thanks a million! -- warm regards, Pradnyesh Sawant -- Be yourself.

Re: doubt with importing module, given module name

2007-04-09 Thread Carsten Haese
On Mon, 2007-04-09 at 22:52 +0530, Pradnyesh Sawant wrote: > Hello, > I have a string which in reality is the name of a module to be > imported. The name of the class contained in the module also has the > same (although with different capitalization). My requirement is to > import the module, and

doubt with importing module, given module name

2007-04-09 Thread Pradnyesh Sawant
Hello, I have a string which in reality is the name of a module to be imported. The name of the class contained in the module also has the same (although with different capitalization). My requirement is to import the module, and also create an instance of the class. eg: str = "module"

Re: Importing module of data dicts and constants

2006-11-25 Thread Fredrik Lundh
Nathan Harmston wrote: > I ve got a single module which I m using to contain a lot of > dictionaries, constants, general information, which are used by > various other modules. However I can't seem to access them: > > in data.py > _SEQTYPE_DNA = 0 > _SEQTYPE_RNA = 1 > _SEQTYPE_PROT = 2 > _seqTy

Re: Importing module of data dicts and constants

2006-11-25 Thread Fuzzyman
Nathan Harmston wrote: > Hi All, > > I ve got a single module which I m using to contain a lot of > dictionaries, constants, general information, which are used by > various other modules. However I can't seem to access them: > > in data.py > _SEQTYPE_DNA = 0 > _SEQTYPE_RNA = 1 > _SEQTYPE_PROT = 2

Importing module of data dicts and constants

2006-11-25 Thread Nathan Harmston
Hi All, I ve got a single module which I m using to contain a lot of dictionaries, constants, general information, which are used by various other modules. However I can't seem to access them: in data.py _SEQTYPE_DNA = 0 _SEQTYPE_RNA = 1 _SEQTYPE_PROT = 2 _seqType = { "DNA":_SEQTYPE_DNA, "RNA":_S