Re: Import issue in python packages

2018-08-11 Thread Peter Otten
Venkatesh Adiga wrote:

> Thanks Peter... What are the ways to update outside of the python program
> without defining environment variable for source code path Otherwise
> can I do it once in during initialization of sys.path update?

I don't understand the question. Your options are

- install your modules/packages in a directory already in sys.path
- put .pth file in a directory already in sys.path
- set PYTHONPATH
- manipulate sys.path at runtime

In my experience the last option has a tendency to break things which is why 
I prefer any of the other ones. It's your choice however.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Import issue in python packages

2018-08-11 Thread Venkatesh Adiga
Thanks Peter... What are the ways to update outside of the python program
without defining environment variable for source code path Otherwise
can I do it once in during initialization of sys.path update?


On Fri, 10 Aug 2018, 10:56 pm Peter Otten, <__pete...@web.de> wrote:

> Venkatesh Adiga wrote:
>
> > Hi All,
> >
> > I am facing issue with python package import.
> > In my project, I have many directories with different python classes
> > defined within them. I am trying to import those classes in another
> python
> > program, but not able to import them.
> > Here are my directories and file structures.
> >   src/platform/operatingsys.py : Defined OperatingSystem Class
> >   src/platform/ipc.py : Defined IPC class
> >   src/platform/MyThread.py: Defined MyThread class
> >   src/platform/__init__.py - zero sized file
> >
> >   src/utils/abc.py
> >   src/utils/def.py
> >   src/utils/__init__.py
> >
> >   src/api/xyz.py
> >   src/api/__init__.py
> >
> >   src/unittest/TestSuite.py - Defined UnitTest Class
> >   src/unittest/__init__.py
> >   src/__init__.py
> >
> >
> > Now, I am trying to use the above classes in another python program(
> > TestPackage.py) as below:
> >
> >
> > *from src.platform.operatingsys import OperatingSystem*
> > .
> > --
> > Execution of TestPackage.py throws an error as below
> >
> >  ImportError: No module named 'src'
> >
> > Currently I have a working code which prefixes sys.path with every
> > directory defined in the package list before import any classes.
> >
> > sys.path.append("src/unittest/")
> > import OperatingSystem
> >
> > But I do not have the hard-coded path and append to sys.path variable.
> > So my question is:
> > 1)  Is there any better way of having the sys.path variable appended by
> > directory listing?
> > 2)  What changes i need to do so that my import statement looks like
> > below:
> >*from src.platform.operatingsys import OperatingSystem*
> >
> > Please suggest...
>
> Ensure that src is in your PYTHONPATH, preferrably as an absolute path.
> Then import the packages and modules without the src prefix, e. g.
>
> sys.path.append("/path/to/src")
> import platform.operatingsys
>
> If you insist on src as part of the import the directory's parent needs to
> be in the path:
>
> sys.path.append("/path/to")
> import src.platform.operatingsys
>
> Note that it's better to avoid manipulating sys.path from within your
> scripts. If at all possible install your packages or at least add .pth
> files
> or a PYTHONPATH environment variable.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Import issue in python packages

2018-08-10 Thread Peter Otten
Venkatesh Adiga wrote:

> Hi All,
> 
> I am facing issue with python package import.
> In my project, I have many directories with different python classes
> defined within them. I am trying to import those classes in another python
> program, but not able to import them.
> Here are my directories and file structures.
>   src/platform/operatingsys.py : Defined OperatingSystem Class
>   src/platform/ipc.py : Defined IPC class
>   src/platform/MyThread.py: Defined MyThread class
>   src/platform/__init__.py - zero sized file
> 
>   src/utils/abc.py
>   src/utils/def.py
>   src/utils/__init__.py
> 
>   src/api/xyz.py
>   src/api/__init__.py
> 
>   src/unittest/TestSuite.py - Defined UnitTest Class
>   src/unittest/__init__.py
>   src/__init__.py
> 
> 
> Now, I am trying to use the above classes in another python program(
> TestPackage.py) as below:
> 
> 
> *from src.platform.operatingsys import OperatingSystem*
> .
> --
> Execution of TestPackage.py throws an error as below
> 
>  ImportError: No module named 'src'
> 
> Currently I have a working code which prefixes sys.path with every
> directory defined in the package list before import any classes.
> 
> sys.path.append("src/unittest/")
> import OperatingSystem
> 
> But I do not have the hard-coded path and append to sys.path variable.
> So my question is:
> 1)  Is there any better way of having the sys.path variable appended by
> directory listing?
> 2)  What changes i need to do so that my import statement looks like
> below:
>*from src.platform.operatingsys import OperatingSystem*
> 
> Please suggest...

Ensure that src is in your PYTHONPATH, preferrably as an absolute path.
Then import the packages and modules without the src prefix, e. g.

sys.path.append("/path/to/src")
import platform.operatingsys

If you insist on src as part of the import the directory's parent needs to 
be in the path:

sys.path.append("/path/to")
import src.platform.operatingsys

Note that it's better to avoid manipulating sys.path from within your 
scripts. If at all possible install your packages or at least add .pth files 
or a PYTHONPATH environment variable.

-- 
https://mail.python.org/mailman/listinfo/python-list


Import issue in python packages

2018-08-10 Thread Venkatesh Adiga
Hi All,

I am facing issue with python package import.
In my project, I have many directories with different python classes
defined within them. I am trying to import those classes in another python
program, but not able to import them.
Here are my directories and file structures.
  src/platform/operatingsys.py : Defined OperatingSystem Class
  src/platform/ipc.py : Defined IPC class
  src/platform/MyThread.py: Defined MyThread class
  src/platform/__init__.py - zero sized file

  src/utils/abc.py
  src/utils/def.py
  src/utils/__init__.py

  src/api/xyz.py
  src/api/__init__.py

  src/unittest/TestSuite.py - Defined UnitTest Class
  src/unittest/__init__.py
  src/__init__.py


Now, I am trying to use the above classes in another python program(
TestPackage.py) as below:


*from src.platform.operatingsys import OperatingSystem*
.
--
Execution of TestPackage.py throws an error as below

 ImportError: No module named 'src'

Currently I have a working code which prefixes sys.path with every
directory defined in the package list before import any classes.

sys.path.append("src/unittest/")
import OperatingSystem

But I do not have the hard-coded path and append to sys.path variable.
So my question is:
1)  Is there any better way of having the sys.path variable appended by
directory listing?
2)  What changes i need to do so that my import statement looks like below:
   *from src.platform.operatingsys import OperatingSystem*

Please suggest...

Thanks
Venkat
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue29837] python3 pycopg2 import issue on solaris 10

2017-03-17 Thread Eric V. Smith

Eric V. Smith added the comment:

This would be an issue for pscyopg2 support, not the Python bug tracker.

You're probably using an unsupported combination of psycopg2 and postgres 
libraries.

--
nosy: +eric.smith
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29837] python3 pycopg2 import issue on solaris 10

2017-03-17 Thread justin

New submission from justin:

Hi,

I have installed psycopg2 through pip3, but when I tried to import it, I got 
the following error. what could be the problem?

help> psycopg2  
problem in psycopg2 - ImportError: ld.so.1: python3.3: fatal: relocation error: 
file /opt/csw/lib/python3.3/site-packages/psycopg2/_psycopg.so: symbol 
timeradd: referenced symbol not found 
 

thanks 

justin

--
components: Build
messages: 289763
nosy: juwang
priority: normal
severity: normal
status: open
title: python3 pycopg2 import issue on solaris 10
type: compile error
versions: Python 3.3

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29837>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



import issue with classes

2012-01-03 Thread Rodrick Brown
I have a class FooB that derives from FooA

i.e.
class FooB(FooA):
  FooA.__init__(self,...)

Can someone explain why

Import FooA doesn't work and I need to use from FooA import FooA instead?
This puzzles me.
Thanks.



-- 
[ Rodrick R. Brown ]
http://www.linkedin.com/in/rodrickbrown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import issue with classes

2012-01-03 Thread Andrew Berg
On 1/3/2012 8:50 PM, Rodrick Brown wrote:
 Import FooA doesn't work and I need to use from FooA import FooA
 instead? This puzzles me. 
 Thanks.
If you have a module called FooA with a class called FooA, then import
FooA imports the /module/. The class would be FooA.FooA, just as the
variable x from FooA would be FooA.x.

-- 
CPython 3.2.2 | Windows NT 6.1.7601.17640
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import issue with classes

2012-01-03 Thread Terry Reedy

On 1/3/2012 10:06 PM, Andrew Berg wrote:

On 1/3/2012 8:50 PM, Rodrick Brown wrote:

Import FooA doesn't work and I need to use from FooA import FooA
instead? This puzzles me.
Thanks.

If you have a module called FooA with a class called FooA, then import
FooA imports the /module/. The class would be FooA.FooA, just as the
variable x from FooA would be FooA.x.


This sort of confusion is why it is not recommended to have file/module 
fooa contain class FooA and why there were some module name changes in Py 3.


--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


Re: import issue with classes

2012-01-03 Thread Benjamin Kaplan
On Tue, Jan 3, 2012 at 9:50 PM, Rodrick Brown rodrick.br...@gmail.com wrote:
 I have a class FooB that derives from FooA

 i.e.
 class FooB(FooA):
   FooA.__init__(self,...)

 Can someone explain why

 Import FooA doesn't work and I need to use from FooA import FooA instead?
 This puzzles me.
 Thanks.



 --
 [ Rodrick R. Brown ]

Because you're coming from Java and thinking that Python behaves the
same way, which isn't true. In Java, every code file consists of a
single public class with the same name as the file. In Python, a
module is an object consisting of many other objects, including
classes, functions, and variables. There's no need for the class name
to be anything related to the file name. By convention, modules
(files) have lowercase names. So lets call your file fooA.py with a
class FooA inside it, just so we can distinguish between them.

import fooA searches for a file called fooA.py in a set of
directories, finds it, compiles it, and binds the now-created module
object to the name fooA. The module object fooA has a class FooA
inside it. They're two separate things.

from fooA import FooA searches for fooA.py, just like before. But
instead of giving you the whole module, it just looks for FooA and
binds it to the same name in the current context.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import issue with classes

2012-01-03 Thread Terry Reedy

On 1/3/2012 11:13 PM, Terry Reedy wrote:

On 1/3/2012 10:06 PM, Andrew Berg wrote:

On 1/3/2012 8:50 PM, Rodrick Brown wrote:

Import FooA doesn't work and I need to use from FooA import FooA
instead? This puzzles me.
Thanks.

If you have a module called FooA with a class called FooA, then import
FooA imports the /module/. The class would be FooA.FooA, just as the
variable x from FooA would be FooA.x.


This sort of confusion is why it is not recommended to have file/module


why it *is* recommended (to have different names) and not recommended to 
have the same name, including case.



fooa contain class FooA and why there were some module name changes in
Py 3.




--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


MySQLdb compiled -- Import issue

2010-03-24 Thread Kurian Thayil
Hi All,

I am just a month old with Python and trying to learn CGI with Python. I
was trying to install MySQLdb module in my new CentOS 5.3 box with
Python 2.4.3 default install. I downloaded the tar-ball of MySQLdb
module (MySQL-python-1.2.3c1). Did build as normal user and install as
root. MySQL server version that I'm using is 5.1.41, if that has
anything to do with the error. I then copied, libmysqlclient_r.so.16
library to /usr/lib/ folder and then I am able to import the module as
root user. But cannot do this as normal user.

Now, while doing import MySQLdb as normal user, I get the following
error message. The scripts will be run as apache and hence cannot have
this error. Please check the following output. Also I have attached the
output while doing build and install process.

[kuria...@server MySQL-python-1.2.3c1]$ python
Python 2.4.3 (#1, Jan 21 2009, 01:10:13) 
[GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2
Type help, copyright, credits or license for more information.
 import MySQLdb
/usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg/_mysql.py:3:
 UserWarning: Module _mysql was already imported from 
/usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg/_mysql.pyc,
 but /opt/downloads/py-modules/MySQL-python-1.2.3c1 is being added to sys.path

It would be a great help if I understand what's going on!!! Thanks in
advance.

Regards,

Kurian Mathew Thayil.
[kuria...@server MySQL-python-1.2.3c1]$ python setup.py build
running build
running build_py
creating build
creating build/lib.linux-i686-2.4
copying _mysql_exceptions.py - build/lib.linux-i686-2.4
creating build/lib.linux-i686-2.4/MySQLdb
copying MySQLdb/__init__.py - build/lib.linux-i686-2.4/MySQLdb
copying MySQLdb/converters.py - build/lib.linux-i686-2.4/MySQLdb
copying MySQLdb/connections.py - build/lib.linux-i686-2.4/MySQLdb
copying MySQLdb/cursors.py - build/lib.linux-i686-2.4/MySQLdb
copying MySQLdb/release.py - build/lib.linux-i686-2.4/MySQLdb
copying MySQLdb/times.py - build/lib.linux-i686-2.4/MySQLdb
creating build/lib.linux-i686-2.4/MySQLdb/constants
copying MySQLdb/constants/__init__.py - 
build/lib.linux-i686-2.4/MySQLdb/constants
copying MySQLdb/constants/CR.py - build/lib.linux-i686-2.4/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py - 
build/lib.linux-i686-2.4/MySQLdb/constants
copying MySQLdb/constants/ER.py - build/lib.linux-i686-2.4/MySQLdb/constants
copying MySQLdb/constants/FLAG.py - build/lib.linux-i686-2.4/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py - 
build/lib.linux-i686-2.4/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py - 
build/lib.linux-i686-2.4/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.linux-i686-2.4
gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -Wall 
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
--param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic 
-fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC -fPIC 
-Dversion_info=(1,2,3,'gamma',1) -D__version__=1.2.3c1 
-I/usr/local/include/mysql -I/usr/include/python2.4 -c _mysql.c -o 
build/temp.linux-i686-2.4/_mysql.o -DUNIV_LINUX -DUNIV_LINUX
In file included from _mysql.c:36:
/usr/local/include/mysql/my_config.h:1050:1: warning: HAVE_WCSCOLL redefined
In file included from /usr/include/python2.4/pyconfig.h:4,
 from /usr/include/python2.4/Python.h:8,
 from pymemcompat.h:10,
 from _mysql.c:29:
/usr/include/python2.4/pyconfig-32.h:648:1: warning: this is the location of 
the previous definition
gcc -pthread -shared build/temp.linux-i686-2.4/_mysql.o -L/usr/local/lib/mysql 
-lmysqlclient_r -lz -lpthread -lcrypt -lnsl -lm -lpthread -o 
build/lib.linux-i686-2.4/_mysql.so
[r...@server MySQL-python-1.2.3c1]# python setup.py install
running install
running bdist_egg
running egg_info
writing MySQL_python.egg-info/PKG-INFO
writing top-level names to MySQL_python.egg-info/top_level.txt
writing dependency_links to MySQL_python.egg-info/dependency_links.txt
reading manifest file 'MySQL_python.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'MySQL_python.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-i686/egg
running install_lib
running build_py
copying MySQLdb/release.py - build/lib.linux-i686-2.4/MySQLdb
running build_ext
creating build/bdist.linux-i686
creating build/bdist.linux-i686/egg
copying build/lib.linux-i686-2.4/_mysql.so - build/bdist.linux-i686/egg
copying build/lib.linux-i686-2.4/_mysql_exceptions.py - 
build/bdist.linux-i686/egg
creating build/bdist.linux-i686/egg/MySQLdb
copying build/lib.linux-i686-2.4/MySQLdb/connections.py - 
build/bdist.linux-i686/egg/MySQLdb
creating build/bdist.linux-i686/egg/MySQLdb/constants
copying build/lib.linux-i686-2.4/MySQLdb/constants/CR.py - 
build/bdist.linux-i686/egg/MySQLdb/constants
copying build/lib.linux-i686-2.4/MySQLdb/constants/__init__.py - 

Re: MySQLdb compiled -- Import issue

2010-03-24 Thread Sean DiZazzo
On Mar 24, 7:59 pm, Kurian Thayil kurianmtha...@gmail.com wrote:
 Hi All,

 I am just a month old with Python and trying to learn CGI with Python. I
 was trying to install MySQLdb module in my new CentOS 5.3 box with
 Python 2.4.3 default install. I downloaded the tar-ball of MySQLdb
 module (MySQL-python-1.2.3c1). Did build as normal user and install as
 root. MySQL server version that I'm using is 5.1.41, if that has
 anything to do with the error. I then copied, libmysqlclient_r.so.16
 library to /usr/lib/ folder and then I am able to import the module as
 root user. But cannot do this as normal user.

 Now, while doing import MySQLdb as normal user, I get the following
 error message. The scripts will be run as apache and hence cannot have
 this error. Please check the following output. Also I have attached the
 output while doing build and install process.

 [kuria...@server MySQL-python-1.2.3c1]$ python
 Python 2.4.3 (#1, Jan 21 2009, 01:10:13)
 [GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2
 Type help, copyright, credits or license for more information. 
 import MySQLdb

 /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg/_mysql.py:3:
  UserWarning: Module _mysql was already imported from 
 /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg/_mysql.pyc,
  but /opt/downloads/py-modules/MySQL-python-1.2.3c1 is being added to sys.path

 It would be a great help if I understand what's going on!!! Thanks in
 advance.

 Regards,

 Kurian Mathew Thayil.

  MySQLdb-build.txt
 3KViewDownload

  MySQLdb-Install.txt
 6KViewDownload

  signature.asc
  1KViewDownload

The warning looks familiar.  Are you running python from the MySQLdb
source directory?  ie.  /opt/downloads/py-modules/MySQL-python-1.2.3c1

I think you just need to change directories and the warning will go
away.  Check what's happening on line 3 of _mysql.py  I don't have the
source in front of me.

~Sean
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MySQLdb compiled -- Import issue

2010-03-24 Thread Kurian Thayil


On Wed, 2010-03-24 at 20:15 -0700, Sean DiZazzo wrote:

 On Mar 24, 7:59 pm, Kurian Thayil kurianmtha...@gmail.com wrote:
  Hi All,
 
  I am just a month old with Python and trying to learn CGI with Python. I
  was trying to install MySQLdb module in my new CentOS 5.3 box with
  Python 2.4.3 default install. I downloaded the tar-ball of MySQLdb
  module (MySQL-python-1.2.3c1). Did build as normal user and install as
  root. MySQL server version that I'm using is 5.1.41, if that has
  anything to do with the error. I then copied, libmysqlclient_r.so.16
  library to /usr/lib/ folder and then I am able to import the module as
  root user. But cannot do this as normal user.
 
  Now, while doing import MySQLdb as normal user, I get the following
  error message. The scripts will be run as apache and hence cannot have
  this error. Please check the following output. Also I have attached the
  output while doing build and install process.
 
  [kuria...@server MySQL-python-1.2.3c1]$ python
  Python 2.4.3 (#1, Jan 21 2009, 01:10:13)
  [GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2
  Type help, copyright, credits or license for more information. 
  import MySQLdb
 
  /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg/_mysql.py:3:
   UserWarning: Module _mysql was already imported from 
  /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg/_mysql.pyc,
   but /opt/downloads/py-modules/MySQL-python-1.2.3c1 is being added to 
  sys.path
 
  It would be a great help if I understand what's going on!!! Thanks in
  advance.
 
  Regards,
 
  Kurian Mathew Thayil.
 
   MySQLdb-build.txt
  3KViewDownload
 
   MySQLdb-Install.txt
  6KViewDownload
 
   signature.asc
   1KViewDownload
 
 The warning looks familiar.  Are you running python from the MySQLdb
 source directory?  ie.  /opt/downloads/py-modules/MySQL-python-1.2.3c1
 
 I think you just need to change directories and the warning will go
 away.  Check what's happening on line 3 of _mysql.py  I don't have the
 source in front of me.
 
 ~Sean


Hi Sean,

You are right. I was trying to import the module sitting on the source
folder :-). Thanks for your quick response and let me try further. 

Regards,

Kurian Mathew Thayil.
attachment: face-embarrassed.png

signature.asc
Description: This is a digitally signed message part
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MySQLdb compiled -- Import issue

2010-03-24 Thread Sean DiZazzo

 You are right. I was trying to import the module sitting on the source
 folder :-). Thanks for your quick response and let me try further.


Sweet!  I remember it because it confused the hell out of me on at
least one past occasion.  :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Import Issue

2006-06-29 Thread praveenkumar . 117
Hi All,

  What is the difference between
   import string
  and 
   from string import *

Regards,
Praveen

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Import Issue

2006-06-29 Thread Ravi Teja
[EMAIL PROTECTED] wrote:
   What is the difference between
import string
   and
from string import *

Here is an explanation.
http://effbot.org/zone/import-confusion.htm

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Import Issue

2006-06-29 Thread Duncan Booth
 wrote:

 Hi All,
 
   What is the difference between
import string
   and 
from string import *
 
 Regards,
 Praveen
 

import string is effectively the same as doing:

string = sys.modules['string']

from string import * is effectively the same as doing:

ascii_letters=sys.modules['string'].ascii_letters
ascii_lowercase=sys.modules['string'].ascii_lowercase
ascii_uppercase=sys.modules['string'].ascii_uppercase
atof=sys.modules['string'].atof
atof_error=sys.modules['string'].atof_error
atoi=sys.modules['string'].atoi
atoi_error=sys.modules['string'].atoi_error
atol=sys.modules['string'].atol
atol_error=sys.modules['string'].atol_error
capitalize=sys.modules['string'].capitalize
capwords=sys.modules['string'].capwords
center=sys.modules['string'].center
count=sys.modules['string'].count
digits=sys.modules['string'].digits
expandtabs=sys.modules['string'].expandtabs
find=sys.modules['string'].find
hexdigits=sys.modules['string'].hexdigits
index=sys.modules['string'].index
index_error=sys.modules['string'].index_error
join=sys.modules['string'].join
joinfields=sys.modules['string'].joinfields
letters=sys.modules['string'].letters
ljust=sys.modules['string'].ljust
lower=sys.modules['string'].lower
lowercase=sys.modules['string'].lowercase
lstrip=sys.modules['string'].lstrip
maketrans=sys.modules['string'].maketrans
octdigits=sys.modules['string'].octdigits
printable=sys.modules['string'].printable
punctuation=sys.modules['string'].punctuation
replace=sys.modules['string'].replace
rfind=sys.modules['string'].rfind
rindex=sys.modules['string'].rindex
rjust=sys.modules['string'].rjust
rsplit=sys.modules['string'].rsplit
rstrip=sys.modules['string'].rstrip
split=sys.modules['string'].split
splitfields=sys.modules['string'].splitfields
strip=sys.modules['string'].strip
swapcase=sys.modules['string'].swapcase
Template=sys.modules['string'].Template
translate=sys.modules['string'].translate
upper=sys.modules['string'].upper
uppercase=sys.modules['string'].uppercase
whitespace=sys.modules['string'].whitespace
zfill=sys.modules['string'].zfill

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Import Issue

2006-06-29 Thread Steve Holden
[EMAIL PROTECTED] wrote:
 Hi All,
 
   What is the difference between
import string
   and 
from string import *
 
[EMAIL PROTECTED] ~/Projects/dbimp
$ python
Python 2.4.1 (#1, May 27 2005, 18:02:40)
[GCC 3.3.3 (cygwin special)] on cygwin
Type help, copyright, credits or license for more information.
Started with C:/Steve/.pythonrc
   dirnow = dir()
   import string
   print [x for x in dir() if x not in dirnow]
['_[1]', 'dirnow', 'string']
  

In the above case something in string is accessed as string.something.

[EMAIL PROTECTED] ~/Projects/dbimp
$ python
Python 2.4.1 (#1, May 27 2005, 18:02:40)
[GCC 3.3.3 (cygwin special)] on cygwin
Type help, copyright, credits or license for more information.
Started with C:/Steve/.pythonrc
   dirnow = dir()
   from string import *
   print [x for x in dir() if x not in dirnow]
['Template', '_[1]', 'ascii_letters', 'ascii_lowercase', 
'ascii_uppercase', 'atof', 'atof_error', 'atoi', 'atoi_error', 'atol', 
'atol_error', 'capitalize', 'capwords', 'center', 'count', 'digits', 
'dirnow', 'expandtabs', 'find', 'hexdigits', 'index', 'index_error', 
'join', 'joinfields', 'letters', 'ljust', 'lower', 'lowercase', 
'lstrip', 'maketrans', 'octdigits', 'printable', 'punctuation', 
'replace', 'rfind', 'rindex', 'rjust', 'rsplit', 'rstrip', 'split', 
'splitfields', 'strip', 'swapcase', 'translate', 'upper', 'uppercase', 
'whitespace', 'zfill']
  

In the second case something from string is inserted directly into the 
current module's namespace, possibly rebinding the name something if 
it already had a value, but you get the convenience of being able to 
access it as something. Not generally regarded as a good idea unless you 
know the package and know it has been designed to be used in this way.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Love me, love my blog  http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

-- 
http://mail.python.org/mailman/listinfo/python-list


Import Issue

2006-06-02 Thread praveenkumar . 117
Hi all,
   I am facing a problem while importing a file in python
script.
   After doing import file i am updating that file. Later i am
accessing a dictionary contained in that
   file. Eventhough changes are reflected in the file... When i
access a dictionary those changes are
   not there. I believe that it is accessing from the object
file that is created when i did import at
   the start of the script. I will be kind enough if somebody
suggest solution to this problem.
Regards-
praveen

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Import Issue

2006-06-02 Thread A.T.Hofkamp
On 2006-06-02, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Hi all,
 After doing import file i am updating that file. Later i am
 accessing a dictionary contained in that
 file. Eventhough changes are reflected in the file... When i
 access a dictionary those changes are
 not there. I believe that it is accessing from the object
 file that is created when i did import at
 the start of the script. I will be kind enough if somebody
 suggest solution to this problem.

The easiest suggestion I can make is don't do that.
An import statement is intended for importing static Python code, not for
importing dynamic data such as dictionaries that you update while running.

Your application is much easier to understand if you keep Python code and data
in seperate files.
For this, there are several options:

A.
If you stick to Python syntax of your data, you can load such files with 'open'
and 'read', followed by 'eval'

fp = open('datafile','r')
datatext = fp.read()
fp.close()
print eval datatext

B.
If you don't care about accessing the data outside Python, you can use the
pickle module to load and save the data.
(please read http://docs.python.org/lib/module-pickle.html for details).

C.
Last but not least, you can define your own data format, and write custom load
and save routines for accessing the data file. This approach is highly
flexible, but it does cost effort to write the routines.


Hope this answer your question,
Albert

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Import Issue

2006-06-02 Thread Maric Michaud
Le Vendredi 02 Juin 2006 08:42, [EMAIL PROTECTED] a écrit :
 Hi all,
After doing import file i am updating that file. Later i am
 accessing a dictionary contained in that
file. Eventhough changes are reflected in the file... When i
 access a dictionary those changes are
not there. I believe that it is accessing from the object
 file that is created when i did import at
the start of the script. I will be kind enough if somebody
 suggest solution to this problem.

Read in the doc the reload builtin description to understand what happens.
But as Albert said before, don't do that !

-- 
_

Maric Michaud
_

Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097
-- 
http://mail.python.org/mailman/listinfo/python-list