Re: List of modules available for import inside Python?

2008-09-07 Thread sc
Gabriel Genellina wrote:

> En Sat, 06 Sep 2008 17:18:55 -0300, clurker <[EMAIL PROTECTED]>
> escribió:
> 
>> Michele Simionato wrote:
>>
>>> On Aug 28, 6:21 am, ssecorp <[EMAIL PROTECTED]> wrote:
>>>> Is there a way to view all the modules I have available for import
>>>> from within Python?
>>>> Like writing in the interpreter:
>>>
>>> Try:
>>>
>>>>>> help()
>>> help> modules
>>> Please wait a moment while I gather a list of all available modules...
>>> 
>>
>> This looks like it could be a useful tool, but when I try it
>> I get the following:
>>
>> Please wait a moment while I gather a list of all available modules...
> [...]
>>   File "/usr/local/lib/python2.5/site-packages/PIL/__init__.py", line
>>   1342,
>> in 
>>
>>   File "/usr/local/lib/python2.5/site-packages/PIL/__init__.py", line
>>   927,
>> in main
>>
>> UnboundLocalError: local variable 'given_files' referenced before
>> assignment
>>>>>
> 
> Unfortunately the "modules" help command actually imports all the
> available packages, and a buggy one may stop the whole process with an
> error.
> 
>> Apparently python knows about them both, but I don't know I
>> haven't introduced an incompatibility somewhere...and that PIL
>> package showing up at the tail of the errors was one of my
>> more recent additions...
> 
> If import of a package fails, the error reported is not accurate. In this
> case, probably some other package failed, that itself imported PIL. Line
> 927 in PIL/__init__.py does not exist.
> 
> A quick fix is to replace line 1854 in pydoc.py (ModuleScanner.run) with
> this one:
> 
> for importer, modname, ispkg in
> pkgutil.walk_packages(onerror=lambda name:None):
> 
> (the onerror argument makes it to ignore all errors)
> 

nice Gabriel, thanx!  At least now "help(); modules" gives me a beautiful
list -- I guess I'll find out what the buggy module is if/when I try
to use it...(all PIL/__init__.py is is about 15 lines of comments 
(referencing a README I can't find))

sc

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

list to tuple conversion

2008-10-01 Thread sc
clp:

Thanx to a recent thread I am able to have a print string
with a variable number of formatters -- what I now lack for
the creation of an elegant print statement is a tuple -- 
following is the code, the last line of which does not work:


#!/usr/bin/python
import xml.sax
import eaddyhandler
parser = xml.sax.make_parser()
h = eaddyhandler.EAddyHandler()
parser.setContentHandler(h)
parser.parse(".ea.xml")
for i in range(1, len(h.m)):
k = "r%06d" % i
col = len(h.m[k])
if col > 2 and h.m[k][0] > " ":
print (col * '%-30s') % h.m[k]


What's going on is I have an oocalc spreadsheet for 
e-addresses -- column 1 has the name, and then I keep 
adding e-addresses for ppl when they get new ones, as 
successive entries on their row, meaning each row has
a variable number of e-address columns.  I have an xml
extractor that runs before this script using 
odf.opendocument, which works famously.

My class, EAddyHandler, also works, and builds its dictionary 
of rows in 'm', forgive me, no flames please, I needed a 
short name for the dictionary I have to type it so many times.
The key to 'm' is an 'r' + row number, so I can get
stuff out of it and it's still in the right order, fun
with dictionaries.

What I was hoping for was something that could vary the
source for the print statement as cleanly as the 'col'
multiplication creates the print format, but the list,
'h.m[k]' is not a tuple, it's a list, and I'm just not 
quite where I am trying to get with this.

If there were a builtin function that took a list and 
returned a tuple, I'd be there, but if there is such a
thing I need someone to point me at it.  I can't help
thinking I am missing some obvious construct, and I'll
be advised to go reread the tutorial, but I'm not there,
and if you can take pity on me and point me there, I'll
be your friend for life.  Well -- I'll be grateful...

TIA,

Scott

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


Re: list to tuple conversion

2008-10-01 Thread sc
Gary M. Josack wrote:

> sc wrote:
>> clp:
>>
>> Thanx to a recent thread I am able to have a print string
>> with a variable number of formatters -- what I now lack for
>> the creation of an elegant print statement is a tuple --
>> following is the code, the last line of which does not work:
>>
>> 
>> #!/usr/bin/python
>> import xml.sax
>> import eaddyhandler
>> parser = xml.sax.make_parser()
>> h = eaddyhandler.EAddyHandler()
>> parser.setContentHandler(h)
>> parser.parse(".ea.xml")
>> for i in range(1, len(h.m)):
>> k = "r%06d" % i
>> col = len(h.m[k])
>> if col > 2 and h.m[k][0] > " ":
>> print (col * '%-30s') % h.m[k]
>> 
>>
>> What's going on is I have an oocalc spreadsheet for
>> e-addresses -- column 1 has the name, and then I keep
>> adding e-addresses for ppl when they get new ones, as
>> successive entries on their row, meaning each row has
>> a variable number of e-address columns.  I have an xml
>> extractor that runs before this script using
>> odf.opendocument, which works famously.
>>
>> My class, EAddyHandler, also works, and builds its dictionary
>> of rows in 'm', forgive me, no flames please, I needed a
>> short name for the dictionary I have to type it so many times.
>> The key to 'm' is an 'r' + row number, so I can get
>> stuff out of it and it's still in the right order, fun
>> with dictionaries.
>>
>> What I was hoping for was something that could vary the
>> source for the print statement as cleanly as the 'col'
>> multiplication creates the print format, but the list,
>> 'h.m[k]' is not a tuple, it's a list, and I'm just not
>> quite where I am trying to get with this.
>>
>> If there were a builtin function that took a list and
>> returned a tuple, I'd be there, but if there is such a
>> thing I need someone to point me at it.  I can't help
>> thinking I am missing some obvious construct, and I'll
>> be advised to go reread the tutorial, but I'm not there,
>> and if you can take pity on me and point me there, I'll
>> be your friend for life.  Well -- I'll be grateful...
>>
>> TIA,
>>
>> Scott
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>   
>  >>> L = [1,2,3,4,5]
>  >>> t = tuple(L)
>  >>> t
> (1, 2, 3, 4, 5)

fine, documented now, for the world to see, I'm an idiot,
fine, but anyway, thank you both, I'll shutup now.

sc

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


Re: Python for the Playstation 3

2008-10-03 Thread sc
Terry Reedy wrote:

> machine.  So this seems a timely idea.  But I don't have a Playstation
> -- yet.
> tjr

have you priced them recently?  I just looked and they are $200
less than the last time I looked -- eeks!  Now _I_ want one!
--
http://mail.python.org/mailman/listinfo/python-list


where to join a open project in Python

2008-01-21 Thread scsoce sc
hi,all:
 as a newbie, i found that finding a suitable open project in Python seems
hard, well, i has tried sourceforge and google code, python project is just
rare or not fit for me. so i want to get any suggestion or experience from
you dear pythonmates.
thank you
scsoce
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: python3 package import difference?

2024-08-07 Thread Ronaldo Sc via Python-list
I believe you will need to track the modules in the folder  *dbi  *in the
root file '__init__.py'.

So there's an alternative to use the statement __all__ in the root filet
__init__.py, check the link where I find a use case:

*https://sentry.io/answers/what-is-init-py-for-in-python/#using-__init__py-to-run-code-and-control--imports
*


References to take more deep in those issues:
PEP-3147 
https://docs.python.org/3/tutorial/modules.html

 in this link above we have some examples of relative imports:
from . import echo
from .. import formats
from ..filters import equalizer


In your code you're using "import *" , this is not a good practice when
using only some features in your module(s) because you'll inject more
garbage into memory if there are features you're not using.

Share with us the updates on your code.

Ronaldo

Em qua., 7 de ago. de 2024 às 14:40, Tobiah via Python-list <
python-list@python.org> escreveu:

> I have an old library from 20 some years ago
> for use with python2, that is structured like this:
>
>  rcs
>  ├── dbi
>  │   ├── __init__.py
>  │   ├── dbi.py
>  │   └── regos.py
>  └── __init__.py  --   *empty*
>
>
> the __init__.py file under 'rcs' is empty.
> The one under rcs.dbi contains:
>
>  from dbi import *
>  from regos import *
>
>
> With python2, I'd go:
>
>  import rcs.dbi
>
> then I'd have access to stuff in regos.py
> as:
>
>  rcs.dbi.feature()  (Where 'feature' is defined in regos.py)
>
>
> When I do the same import with python3, I get:
>
>  Traceback (most recent call last):
>File "/home/toby/me", line 1, in 
>  import rcs.dbi
>File "/usr/regos-1.0/lib/python/rcs/dbi/__init__.py", line 1, in
> 
>  from dbi import *
>  ModuleNotFoundError: No module named 'dbi'
>
>
> What's changed, and how do I fix it?
>
>
> Thanks!
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list