Re: Tree structure

2011-07-26 Thread Marco Nawijn
On Jul 26, 6:53 am, Bevan Jenkins  wrote:
> Hello,
>
> I am trying to create a tree structure for use with a PyQt QTreeView.
> But first I need to get my head around how to create the tree
> structure.  I have a dictionary (for testing purposes) but I will
> later use a table via sqlalchemy.
>
> The use case is hydrology, so I  would like to have a hydrologically
> connected river tree, in which you can browse upstream from the sea
> (making choices) or downstream from any named hydrological feature.
> Each key flows into its value pair. myrivers =
> {"river":"flows_into"}.  An example is below:
>
> myrivers = {"little stream":"sea",
>     "mountain stream":"lake",
>     "lake":"big river",
>     "cold spring":"big river",
>     "big river":"sea"
>     "sea":""}
>
> I would like the tree to look like (if the formatting works). so
> you can browse downstream from each named river but also upstream from
> the sea picking which direction to go.
>
> little stream
>     sea
> mountain stream
>     lake
>         big river
>             sea
> lake
>     big river
>         sea
> cold spring
>     big river
>         sea
> big river
>     sea
> sea
>     little stream
>     big river
>         lake
>             mountain stream
>         cold spring
>
> <>
> So every key is a parent.  For all keys that have a value (not ""),
> the value is the child and is then used as a parent to get the next
> child until the sea and a value of "" is reached.  For the sea this is
> reversed, that you find all rivers that flow into the sea and then all
> rivers that flow into them.
>
> Any thoughts about how to acomplish this will be much appreciated,
> Bevan

Hello Bevan,

Is it an option to use XML as an in-memory representation. It
naturally provides the
interface you need, like traversing from parent to children and back.
In addition, you
get querying capabilities like XPATH for free. In python I recommend
lxml.

Your task than is to fill the tree based on the information in the
database. The ORM functionality
from sqlalchemy will be of help here. In addition, you somehow have to
populate the QT tree with the
data from your in-memory XML representation. I have no experience with
QT so I cannot help you there.

Regards,

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


Re: reportlab import error after dundled using py2exe

2011-07-26 Thread SANKAR .
your suggestion worked.Thanks Robin.

-Sankar

On Mon, Jul 25, 2011 at 8:28 PM, Robin Becker  wrote:

> On 22/07/2011 03:55, SANKAR . wrote:
>
>> Hi all,
>>
>> 
>
>
>> C:\Python26\dist>DELchek.exe
>> Traceback (most recent call last):
>> File "DELchek.py", line 12, in
>> File "reportlab\pdfgen\canvas.pyc", line 25, in<
>> File "reportlab\pdfbase\pdfdoc.pyc"**, line 22, in
>> File "reportlab\pdfbase\pdfmetrics.**pyc", line 23,
>> File "reportlab\pdfbase\_fontdata.**pyc", line 158,
>> ImportError: No module named _fontdata_enc_winansi
>>
>> But I could see the '_fontdata_enc_winansi' module in reportlab folder.
>> Could someone help me to fix this.
>>
>> .
> You can try asking this in the reportlab list
>
> reportlab-users@lists2.**reportlab.com
>
> but perhaps this is more about py2exe than reportlab. The modules
> _fontdata_enc_* & _fontdata_widths_* are imported dynamically in
> _fontdata.py rather than explicitly. I suspect that py2exe needs to be given
> a hint that this is going on. However, I'm uncertain as to why this should
> be required since even if the imports are being dynamically imported that is
> done as soon as _fontdata is imported (ie it's part of the module code) so
> those modules should be seen by the setup.py.
>
> If you don't have reportlab explicitly imported as part of the packages try
> adding this to the packages list
>
>packages=[
>
> ..**..
>
>
>'reportlab',
>'reportlab.graphics.charts',
>'reportlab.graphics.samples',
>'reportlab.graphics.widgets',
>'reportlab.graphics.barcode',
>'reportlab.graphics',
>'reportlab.lib',
>'reportlab.pdfbase',
>'reportlab.pdfgen',
>'reportlab.platypus',
>],
>
>
> that's what we use to make the distributions and seems to work.
> --
> Robin Becker
>
> --
> http://mail.python.org/**mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Selecting unique values

2011-07-26 Thread Kumar Mainali
Greetings

I have a dataset with occurrence records of multiple species. I need to get
rid of multiple listings of the same occurrence point for a species (as you
see below in red and blue typeface). How do I create a dataset only with
unique set of longitude and latitude for each species? Thanks in advance.

Species_name Longitude Latitude
Abies concolor -106.601 35.868
Abies concolor -106.493 35.9682
Abies concolor -106.489 35.892
Abies concolor -106.496 35.8542
Accipiter cooperi -119.688 34.4339
Accipiter cooperi -119.792 34.5069
Accipiter cooperi -118.797 34.2581
Accipiter cooperi -77.38333 39.68333
Accipiter cooperi -77.38333 39.68333
Accipiter cooperi -75.99153 40.65
Accipiter cooperi -75.99153 40.65

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


Re: Selecting unique values

2011-07-26 Thread Chris Angelico
On Tue, Jul 26, 2011 at 8:03 AM, Kumar Mainali  wrote:
> Greetings
>
> I have a dataset with occurrence records of multiple species. I need to get
> rid of multiple listings of the same occurrence point for a species (as you
> see below in red and blue typeface). How do I create a dataset only with
> unique set of longitude and latitude for each species? Thanks in advance.
> Species_name Longitude Latitude
> Abies concolor -106.601 35.868
> Abies concolor -106.493 35.9682
> Abies concolor -106.489 35.892
> Abies concolor -106.496 35.8542
> Accipiter cooperi -119.688 34.4339
> Accipiter cooperi -119.792 34.5069
> Accipiter cooperi -118.797 34.2581
> Accipiter cooperi -77.38333 39.68333
> Accipiter cooperi -77.38333 39.68333
> Accipiter cooperi -75.99153 40.65
> Accipiter cooperi -75.99153 40.65

Pass the file through the 'uniq' utility, on Unix. Easy.

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


Re: Tree structure

2011-07-26 Thread Peter Otten
Bevan Jenkins wrote:

> Hello,
> 
> I am trying to create a tree structure for use with a PyQt QTreeView.
> But first I need to get my head around how to create the tree
> structure.  I have a dictionary (for testing purposes) but I will
> later use a table via sqlalchemy.
> 
> The use case is hydrology, so I  would like to have a hydrologically
> connected river tree, in which you can browse upstream from the sea
> (making choices) or downstream from any named hydrological feature.
> Each key flows into its value pair. myrivers =
> {"river":"flows_into"}.  An example is below:
> 
> myrivers = {"little stream":"sea",
> "mountain stream":"lake",
> "lake":"big river",
> "cold spring":"big river",
> "big river":"sea"
> "sea":""}
> 
> I would like the tree to look like (if the formatting works). so
> you can browse downstream from each named river but also upstream from
> the sea picking which direction to go.
> 
> little stream
> sea
> mountain stream
> lake
> big river
> sea
> lake
> big river
> sea
> cold spring
> big river
> sea
> big river
> sea
> sea
> little stream
> big river
> lake
> mountain stream
> cold spring
> 
> <>
> So every key is a parent.  For all keys that have a value (not ""),
> the value is the child and is then used as a parent to get the next
> child until the sea and a value of "" is reached.  For the sea this is
> reversed, that you find all rivers that flow into the sea and then all
> rivers that flow into them.
> 
> 
> Any thoughts about how to acomplish this will be much appreciated,
> Bevan

If you turn the values into lists you can use the same function for both 
trees:

INDENT = " " * 4

def print_tree(lookup, node=None):
def _tree(node, level):
print "%s%s" % (INDENT * level, node)
for node in lookup.get(node, ()):
_tree(node, level+1)

if node is None:
for node in lookup:
_tree(node, 0)
else:
_tree(node, 0)

def reversed_dict(tree):
reversed_tree = {}
for key, values in rivers.iteritems():
for value in values:
reversed_tree.setdefault(value, []).append(key)
return reversed_tree

if __name__ == "__main__":
rivers = {
"little stream": "sea",
"mountain stream": "lake",
"lake": "big river",
"cold spring": "big river",
"big river": "sea",
"see": ""}

rivers = dict((k, [v]) for k, v in rivers.iteritems() if v)
print_tree(rivers)
print "---"
print_tree(reversed_dict(rivers), "sea")


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


Re: Selecting unique values

2011-07-26 Thread sparky gmail

On 7/25/2011 3:03 PM, Kumar Mainali wrote:

Greetings

I have a dataset with occurrence records of multiple species. I need 
to get rid of multiple listings of the same occurrence point for a 
species (as you see below in red and blue typeface). How do I create a 
dataset only with unique set of longitude and latitude for each 
species? Thanks in advance.


Species_nameLongitudeLatitude
Abies concolor-106.60135.868
Abies concolor-106.49335.9682
Abies concolor-106.48935.892
Abies concolor-106.49635.8542
Accipiter cooperi-119.68834.4339
Accipiter cooperi-119.79234.5069
Accipiter cooperi-118.79734.2581
Accipiter cooperi-77.389.68333
Accipiter cooperi-77.389.68333
Accipiter cooperi-75.9915340.65
Accipiter cooperi-75.9915340.65

- Kumar
It would seem to me that what you are wanting is a dictionary where the 
species name is the key and the value is a list of Long/Lat


So assuming your data is in a list like so (such as you might get from 
reading lines from a file) ['Abies concolor-106.60135.868', 'Abies 
concolor-106.49335.9682']


You could say

output = dict()
for record in my_long_list:
values = record.rsplit(' ', 2)
key = values[:1]
value = ' '.join(values[1:])
try:
 output[key].append(value)
 except KeyError:
 output[key] = [value]


Something like that should do.


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


Re: Selecting unique values

2011-07-26 Thread Peter Otten
Kumar Mainali wrote:

> I have a dataset with occurrence records of multiple species. I need to
> get rid of multiple listings of the same occurrence point for a species
> (as you see below in red and blue typeface). How do I create a dataset
> only with unique set of longitude and latitude for each species? Thanks in
> advance.
> 
> Species_name Longitude Latitude
> Abies concolor -106.601 35.868
> Abies concolor -106.493 35.9682
> Abies concolor -106.489 35.892
> Abies concolor -106.496 35.8542
> Accipiter cooperi -119.688 34.4339
> Accipiter cooperi -119.792 34.5069
> Accipiter cooperi -118.797 34.2581
> Accipiter cooperi -77.38333 39.68333
> Accipiter cooperi -77.38333 39.68333
> Accipiter cooperi -75.99153 40.65
> Accipiter cooperi -75.99153 40.65

>>> def uniquify(items):
... seen = set()
... for item in items:
... if item not in seen:
... seen.add(item)
... yield item
...
>>> import sys
>>> sys.stdout.writelines(uniquify(open("species.txt")))
Species_name Longitude Latitude
Abies concolor -106.601 35.868
Abies concolor -106.493 35.9682
Abies concolor -106.489 35.892
Abies concolor -106.496 35.8542
Accipiter cooperi -119.688 34.4339
Accipiter cooperi -119.792 34.5069
Accipiter cooperi -118.797 34.2581
Accipiter cooperi -77.38333 39.68333
Accipiter cooperi -75.99153 40.65

If you need to massage the lines a bit:

>>> def uniquify(items, key=None):
... seen = set()
... for item in items:
... if key is None:
... keyval = item
... else:
... keyval = key(item)
... if keyval not in seen:
... seen.add(keyval)
... yield item
...

Unique latitudes:

>>> sys.stdout.writelines(uniquify(open("species.txt"), key=lambda s: 
s.rsplit(None, 1)[-1]))
Species_name Longitude Latitude
Abies concolor -106.601 35.868
Abies concolor -106.493 35.9682
Abies concolor -106.489 35.892
Abies concolor -106.496 35.8542
Accipiter cooperi -119.688 34.4339
Accipiter cooperi -119.792 34.5069
Accipiter cooperi -118.797 34.2581
Accipiter cooperi -77.38333 39.68333
Accipiter cooperi -75.99153 40.65

Unique species names:

>>> sys.stdout.writelines(uniquify(open("species.txt"), key=lambda s: 
s.rsplit(None, 2)[0]))
Species_name Longitude Latitude
Abies concolor -106.601 35.868
Accipiter cooperi -119.688 34.4339

Bonus: open() is not the built-in here:

>>> from StringIO import StringIO
>>> def open(filename):  
... return StringIO("""Species_name Longitude Latitude
... Abies concolor -106.601 35.868
... Abies concolor -106.493 35.9682   
... Abies concolor -106.489 35.892
... Abies concolor -106.496 35.8542   
... Accipiter cooperi -119.688 34.4339
... Accipiter cooperi -119.792 34.5069
... Accipiter cooperi -118.797 34.2581
... Accipiter cooperi -77.38333 39.68333  
... Accipiter cooperi -77.38333 39.68333  
... Accipiter cooperi -75.99153 40.65 
... Accipiter cooperi -75.99153 40.65 
... """)  
...   


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


Re: Trying to learn about metaclasses

2011-07-26 Thread Thomas Jollans
On 26/07/11 04:44, Victor Khangulov wrote:
> Hi Steven,
> 
> I too am just learning about metaclasses in Python and I found the
> example you posted to be excellent.
> 
> I played around with it and noticed that the issue seems to be the
> double-underscore in front of the fields (cls.__fields = {}).  If you
> change this parameter to use the single-underscore, the code works
> perfectly.

Hate to disappoint you, but there never was a double underscore. (That
would be a problem, of course, but, as Peter pointed out, __init was the
actual problem)

> 
> I think that because of the double-underscore, the name of the attribute
> "fields" gets mangled by the interpreter and is not inherited from the
> parent class in its accessible form.  Now, I am not sure if the code
> posted uses an earlier version of Python where these rule are different
> or if there is a more correct way to achieve this.  I will follow this
> discussion to see if someone has a better answer.
> 
> -victor

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


Re: ActivePython: multiple versions on OSX?

2011-07-26 Thread John Roth
On Jul 25, 8:18 pm, Ned Deily  wrote:
> In article , Robert 
> wrote:
>
> > Is it possible to install the 2 and 3 series side by side?
>
> Probably.  On Mac OS X, t's certainly possible to install any python.org
> versions side by side, even multiple versions of 2 and 3.  That's one of
> the advantages of the Python framework build layout on OS X, which is
> used by both the python.org installers and, I believe, the ActiveState
> installers.
>
> http://www.python.org/download/
>
> --
>  Ned Deily,
>  n...@acm.org

When you do, you might also want to look at PEP 394:
http://www.python.org/dev/peps/pep-0394/

It can simplify writing scripts which select the version you want.

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


Convolution of different sized arrays

2011-07-26 Thread Olenka Subota
Hello all,

I need your help. I have to simulate a filter whose transfer function
is a step fct, and I wrote it as a column-vector of Ns elements :
>>> h=ones(3,dtype=float)
>>> print h
[ 1.  1.  1.]
>>> h=reshape(h,(3,1))
>>> h
array([[ 1.],
   [ 1.],
   [ 1.]])

In this case Ns=3 for simplicity.
The input of my filter is another column-vector of k*Ns elements
(3*3):
x0_vect
array([[ 1.41421356],
   [ 0.],
   [ 0.],
   [ 1.41421356],
   [ 0.],
   [ 0.],
   [ 1.41421356],
   [ 0.],
   [ 0.]])
So I`d like to convolve the two column vectors. Am I going to obtain a
row-vector?
I`ve tried to apply the convolve built-in function but it gives me
this error:
convolve(x0_vect,h)

Traceback (most recent call last):
  File "", line 1, in 
convolve(x0_vect,h)
  File "C:\Python27\lib\site-packages\numpy\core\numeric.py", line
787, in convolve
return multiarray.correlate(a, v[::-1], mode)
ValueError: object too deep for desired array

If anyone of you can help, please do it..
Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


reading zipfile; problem using raw buffer

2011-07-26 Thread Sells, Fred
I'm tring to unzip a buffer that is uploaded to django/python.  I can
unzip the file in batch mode just fine, but when I get the buffer I get
a "BadZipfile exception.  I wrote this snippet to try to isolate the
issue but I don't understand what's going on.  I'm guessing that I'm
losing some header/trailer somewhere?

def unittestZipfile(filename):
buffer = ''
f = open(filename)
for i in range(22):
block = f.read()
if len(block) == 0: 
break
else:
buffer += block

print len(buffer)
tmp = open('tmp.zip', 'w')
tmp.write(buffer)
tmp.close()
zf = zipfile.ZipFile('tmp.zip')
print dir(zf)
for name in zf.namelist():
print name
print zf.read(name)

2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)]
Traceback (most recent call last):
  File
"C:\all\projects\AccMDS30Server\mds30\app\uploaders\xmitzipfile.py",
line 162, in 
unittestZipfile('wk1live7.8to7.11.zip')
  File
"C:\all\projects\AccMDS30Server\mds30\app\uploaders\xmitzipfile.py",
line 146, in unittestZipfile
print zf.read(name)
  File "C:\alltools\python26\lib\zipfile.py", line 837, in read
return self.open(name, "r", pwd).read()
  File "C:\alltools\python26\lib\zipfile.py", line 867, in open
raise BadZipfile, "Bad magic number for file header"
zipfile.BadZipfile: Bad magic number for file header

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


Re: Convolution of different sized arrays

2011-07-26 Thread Billy Mays

On 07/26/2011 08:10 AM, Olenka Subota wrote:

If anyone of you can help, please do it..
Thanks!


You would probably get a better answer asking on one of the mailing 
lists here: http://new.scipy.org/mailing-lists.html

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


Re: PEP 8 and extraneous whitespace

2011-07-26 Thread AlienBaby
> (on limiting line lengths)..

I didn't see this mentioned;

I have a hard time keeping python code limited to 80 char line lengths
_because_ indentation is significant, and can end up consuming quite a
lot of linespace itself.  Couple that with a liking for
long_memorable_explanatory_names, and an 80 char limit causes (me)
problems.

So I tend to use the print margin just as a guide. If I am over it,
then don't panic! just don't put any new elements onto the line, and
maybe step back and think about what your doing just in case theres
another clear way that avoids the issue.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reading zipfile; problem using raw buffer

2011-07-26 Thread Billy Mays

On 07/26/2011 08:42 AM, Sells, Fred wrote:

I'm tring to unzip a buffer that is uploaded to django/python.  I can
unzip the file in batch mode just fine, but when I get the buffer I get
a "BadZipfile exception.  I wrote this snippet to try to isolate the
issue but I don't understand what's going on.  I'm guessing that I'm
losing some header/trailer somewhere?

def unittestZipfile(filename):
 buffer = ''
 f = open(filename)
 for i in range(22):
 block = f.read()
 if len(block) == 0:
 break
 else:
 buffer += block

 print len(buffer)
 tmp = open('tmp.zip', 'w')
 tmp.write(buffer)
 tmp.close()
 zf = zipfile.ZipFile('tmp.zip')
 print dir(zf)
 for name in zf.namelist():
 print name
 print zf.read(name)

2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)]
Traceback (most recent call last):
   File
"C:\all\projects\AccMDS30Server\mds30\app\uploaders\xmitzipfile.py",
line 162, in
 unittestZipfile('wk1live7.8to7.11.zip')
   File
"C:\all\projects\AccMDS30Server\mds30\app\uploaders\xmitzipfile.py",
line 146, in unittestZipfile
 print zf.read(name)
   File "C:\alltools\python26\lib\zipfile.py", line 837, in read
 return self.open(name, "r", pwd).read()
   File "C:\alltools\python26\lib\zipfile.py", line 867, in open
 raise BadZipfile, "Bad magic number for file header"
zipfile.BadZipfile: Bad magic number for file header



You need to specify the file mode since I'm guessing you use Windows 
from the traceback:


f = open(filename, 'rb')

and later:

tmp = open('tmp.zip', 'wb')

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


Re: reading zipfile; problem using raw buffer

2011-07-26 Thread Peter Otten
Sells, Fred wrote:

> I'm tring to unzip a buffer that is uploaded to django/python.  I can
> unzip the file in batch mode just fine, but when I get the buffer I get
> a "BadZipfile exception.  I wrote this snippet to try to isolate the
> issue but I don't understand what's going on.  I'm guessing that I'm
> losing some header/trailer somewhere?

Why are you copying the file before you try to unzip it?

> def unittestZipfile(filename):
> buffer = ''
> f = open(filename)

Open the file in binary mode:

  f = open(filename, "rb")

> for i in range(22):
> block = f.read()
> if len(block) == 0:
> break
> else:
> buffer += block
> print len(buffer)
> tmp = open('tmp.zip', 'w')

Again, open the file in binary mode ("wb").

> tmp.write(buffer)
> tmp.close()

Not essential to the problem you are encountering, but you want 
shutil.copyfile(). Also, have a look at the shutil.copyfileobj() 
implementation to learn how to properly copy a file in chunks of limited 
size.

> zf = zipfile.ZipFile('tmp.zip')
> print dir(zf)
> for name in zf.namelist():
> print name
> print zf.read(name)
> 
> 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)]
> Traceback (most recent call last):
>   File
> "C:\all\projects\AccMDS30Server\mds30\app\uploaders\xmitzipfile.py",
> line 162, in 
> unittestZipfile('wk1live7.8to7.11.zip')
>   File
> "C:\all\projects\AccMDS30Server\mds30\app\uploaders\xmitzipfile.py",
> line 146, in unittestZipfile
> print zf.read(name)
>   File "C:\alltools\python26\lib\zipfile.py", line 837, in read
> return self.open(name, "r", pwd).read()
>   File "C:\alltools\python26\lib\zipfile.py", line 867, in open
> raise BadZipfile, "Bad magic number for file header"
> zipfile.BadZipfile: Bad magic number for file header


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


Annoucing BRss Feed Reader

2011-07-26 Thread Bidossessi SODONON

Hi list.
I've written an offline RSS client using python-gobject and python-dbus.

https://sourceforge.net/projects/brss/

Please check it out, and give feedback on how to make it better 
(especially memory-wise).

Any contribution would be greatly appreciated.


If this is not the right place for this kind of annoucment, I apologize.
--
http://mail.python.org/mailman/listinfo/python-list


Is this overuse a context manager?

2011-07-26 Thread Neil Cerutti
I use them all the time now, even when the resource being managed
is used for just one line, and never need be assigned an explicit
name. Is it good style, or annoying?

with open(in_fname, newline='') as in_file:
folk = list(csv.DictReader(in_file))

The obvious alternative is:

folk = list(csv.DictReader(open(in_fname, newline='')))

With the many files I have to process, I find the with statements
create a visual structure that is helpful to track how many files
I'm working with at once.

The existence of the context also usually forces me to think more
carefully about how long I really need that resource.

But maybe I'm being a bit zeallous.

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


Re: abort python script from trace function

2011-07-26 Thread Dave Stark
Update:

I ended getting the desired result by registering a new trace function.  In my 
existing trace function I check the status of the abort button.  When it's been 
triggered I register a NEW trace function using PyEval_SetTrace.  I also use 
PyEval_SetProfile and point them both at my new trace function.  The new trace 
function just raises a python exception using PyErr_SetString.  Then I return 
-1 from the trace function.  It gets called several times but eventually the 
script dies.  This works even when the python script running is an insane set 
of nested try/except loops.
-- 
http://mail.python.org/mailman/listinfo/python-list


Only Bytecode, No .py Files

2011-07-26 Thread Eldon Ziegler
Is there a way to have the Python processor look only for bytecode
files, not .py files? We are seeing huge numbers of Linux audit messages
on production system on which only bytecode files are stored. The audit
subsystem is recording each open failure.

Thanks,
Eldon Ziegler


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


RE: reading zipfile; problem using raw buffer

2011-07-26 Thread Sells, Fred
Thanks all,  adding the 'rb' and 'wb' solved that test case.

The reason I read the file "the hard way" is that I'm testing why I
cannot unzip a buffer passed in a file upload using django.

While not actually using a file, pointing out the need for the binary
option gave me the clue I needed to upload the file

All is good and moving on to the next crisis ;)

Fred.


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


Re: Only Bytecode, No .py Files

2011-07-26 Thread Billy Mays

On 07/26/2011 11:19 AM, Eldon Ziegler wrote:

Is there a way to have the Python processor look only for bytecode
files, not .py files? We are seeing huge numbers of Linux audit messages
on production system on which only bytecode files are stored. The audit
subsystem is recording each open failure.

Thanks,
Eldon Ziegler




How are you opening your files?

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


Re: ActivePython: multiple versions on OSX?

2011-07-26 Thread Melton Low
On Tue, Jul 26, 2011 at 9:53 AM, Web Dreamer  wrote:

> John Roth a écrit ce mardi 26 juillet 2011 14:00 dans <75342033-
> abbb-4d59-9654-96d5031dc...@r28g2000prb.googlegroups.com> :
>
> > On Jul 25, 8:18 pm, Ned Deily  wrote:
> >> In article , Robert 
> >> wrote:
> >>
> >> > Is it possible to install the 2 and 3 series side by side?
> [...]
> > When you do, you might also want to look at PEP 394:
> > http://www.python.org/dev/peps/pep-0394/
> >
> > It can simplify writing scripts which select the version you want.
>
>
> http://www.python.org/dev/peps/pep-0394/#impact-on-python-environment-variables
> What would be a nice feature would be having:
> PYTHONPATH (and PYTHONHOME, etc) referring to all versions, and to allow
> having PYTHON2PATH, PYTHON2HOME (and PYTHON3PATH, PYTHON3HOME), etc... for
> the specific versions.
> This would allow having global variables for all versions, and special
> variables for specific versions, to allow more flexibility.
> Or would it be silly?
>
> --
> Web Dreamer
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

It's probably impractical.  You would need a pair for each version of Python
installed, ie. (PYTHON26PATH,PYTHON26HOME) for 2.6.x,
(PYTHON27PATH,PYTHON27HOME) for 2.7.x,  for 3.1.x, for 3.2.x, etc).  Not
just one set for the 2.x series and another for the 3.x series.  Some
developer may have 2.5.x, 2.6.x, 2.7.x, 3.1.x and 3.2.x installed.  These
environment variables have to be set somewhere, probably in your personal
shell startup script or the system-wide shell startup script, which have to
be maintained.  Even with all those environment variables set, you would
still have to invoke the version of Python you want in order for it to
pickup the variable.

On Mac OS X, a link is automatically installed in /usr/local/bin for each
version of the Python executables, ie python2.7 for the 2.7.x  and python3.2
for 3.2.x.  Just invoke your script with the appropriate Python version.
 eg. python3.2 yourscript to run 'yourscript'.

Other people will have different ideas.

Cheer, Mel
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ActivePython: multiple versions on OSX?

2011-07-26 Thread Chris Angelico
On Wed, Jul 27, 2011 at 2:33 AM, Melton Low  wrote:
> It's probably impractical.  You would need a pair for each version of Python
> installed, ie. (PYTHON26PATH,PYTHON26HOME) for 2.6.x,
> (PYTHON27PATH,PYTHON27HOME) for 2.7.x,  for 3.1.x, for 3.2.x, etc).

You could set up a script for each version that looks for environment
variables in the right order, stopping when it finds one. Version
3.2.1 would look for PYTHON321PATH, then PYTHON32PATH, then
PYTHON3PATH, finally falling back on PYTHONPATH. It could then put the
appropriate path into PYTHONPATH (not overwriting the external
variable of the same name - if your shell doesn't do that for you,
just save it to restore later), and invoke Python.

Still seems fairly cumbersome, and doesn't handle the possibility of
having two separate installs of the same version number (different
builds of 3.3, or 32-bit and 64-bit Pythons, or something). It may be
easier to simply create some scripts that set up the environment
explicitly, and then invoke Python. Name 'em according to what you
want of them.

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


Re: Only Bytecode, No .py Files

2011-07-26 Thread Miki Tebeka
*Maybe* you can cook something with import hooks (see PEP 302). However I think 
the easier option will be to distribute the .py files as well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ActivePython: multiple versions on OSX?

2011-07-26 Thread Jeremiah Yongue
It's definitely possible. I've done it myself.
On Jul 25, 2011 8:21 PM, "Robert"  wrote:
> Is it possible to install the 2 and 3 series side by side?
>
> --
> Robert
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Selecting unique values

2011-07-26 Thread Sells, Fred
The set module or function (depends on which python version) will do
this if you make each record a tuple.

-Original Message-
From: python-list-bounces+frsells=adventistcare@python.org
[mailto:python-list-bounces+frsells=adventistcare@python.org] On
Behalf Of Peter Otten
Sent: Tuesday, July 26, 2011 5:04 AM
To: python-list@python.org
Subject: Re: Selecting unique values

Kumar Mainali wrote:

> I have a dataset with occurrence records of multiple species. I need
to
> get rid of multiple listings of the same occurrence point for a
species
> (as you see below in red and blue typeface). How do I create a dataset
> only with unique set of longitude and latitude for each species?
Thanks in
> advance.
> 
> Species_name Longitude Latitude
> Abies concolor -106.601 35.868
> Abies concolor -106.493 35.9682
> Abies concolor -106.489 35.892
> Abies concolor -106.496 35.8542
> Accipiter cooperi -119.688 34.4339
> Accipiter cooperi -119.792 34.5069
> Accipiter cooperi -118.797 34.2581
> Accipiter cooperi -77.38333 39.68333
> Accipiter cooperi -77.38333 39.68333
> Accipiter cooperi -75.99153 40.65
> Accipiter cooperi -75.99153 40.65

>>> def uniquify(items):
... seen = set()
... for item in items:
... if item not in seen:
... seen.add(item)
... yield item
...
>>> import sys
>>> sys.stdout.writelines(uniquify(open("species.txt")))
Species_name Longitude Latitude
Abies concolor -106.601 35.868
Abies concolor -106.493 35.9682
Abies concolor -106.489 35.892
Abies concolor -106.496 35.8542
Accipiter cooperi -119.688 34.4339
Accipiter cooperi -119.792 34.5069
Accipiter cooperi -118.797 34.2581
Accipiter cooperi -77.38333 39.68333
Accipiter cooperi -75.99153 40.65

If you need to massage the lines a bit:

>>> def uniquify(items, key=None):
... seen = set()
... for item in items:
... if key is None:
... keyval = item
... else:
... keyval = key(item)
... if keyval not in seen:
... seen.add(keyval)
... yield item
...

Unique latitudes:

>>> sys.stdout.writelines(uniquify(open("species.txt"), key=lambda s: 
s.rsplit(None, 1)[-1]))
Species_name Longitude Latitude
Abies concolor -106.601 35.868
Abies concolor -106.493 35.9682
Abies concolor -106.489 35.892
Abies concolor -106.496 35.8542
Accipiter cooperi -119.688 34.4339
Accipiter cooperi -119.792 34.5069
Accipiter cooperi -118.797 34.2581
Accipiter cooperi -77.38333 39.68333
Accipiter cooperi -75.99153 40.65

Unique species names:

>>> sys.stdout.writelines(uniquify(open("species.txt"), key=lambda s: 
s.rsplit(None, 2)[0]))
Species_name Longitude Latitude
Abies concolor -106.601 35.868
Accipiter cooperi -119.688 34.4339

Bonus: open() is not the built-in here:

>>> from StringIO import StringIO
>>> def open(filename):  
... return StringIO("""Species_name Longitude Latitude
... Abies concolor -106.601 35.868
... Abies concolor -106.493 35.9682   
... Abies concolor -106.489 35.892
... Abies concolor -106.496 35.8542   
... Accipiter cooperi -119.688 34.4339
... Accipiter cooperi -119.792 34.5069
... Accipiter cooperi -118.797 34.2581
... Accipiter cooperi -77.38333 39.68333  
... Accipiter cooperi -77.38333 39.68333  
... Accipiter cooperi -75.99153 40.65 
... Accipiter cooperi -75.99153 40.65 
... """)  
...   


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

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


Re: Is this overuse a context manager?

2011-07-26 Thread Ethan Furman

Neil Cerutti wrote:

I use them all the time now, even when the resource being managed
is used for just one line, and never need be assigned an explicit
name. Is it good style, or annoying?

with open(in_fname, newline='') as in_file:
folk = list(csv.DictReader(in_file))

The obvious alternative is:

folk = list(csv.DictReader(open(in_fname, newline='')))


I can see that it might take some getting used to, but I suspect the 
context managers are the better style: it clearly denotes the lifespan 
of the managed object, and provides for resource clean-up.  (I know, 
files are already automatically cleaned up -- at least in cpython; but 
not every managed object will be a file.)


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


Re: Is this overuse a context manager?

2011-07-26 Thread Terry Reedy

On 7/26/2011 9:24 AM, Neil Cerutti wrote:

I use them all the time now, even when the resource being managed
is used for just one line, and never need be assigned an explicit
name. Is it good style, or annoying?


Annoying to you? or an actual or imagined audience?


 with open(in_fname, newline='') as in_file:
 folk = list(csv.DictReader(in_file))


This closes the file immediately.


The obvious alternative is:

 folk = list(csv.DictReader(open(in_fname, newline='')))


This happens to close the file immediately on current CPython since the 
file object is immediately deleted, but will not on some other 
implementations. If a process only opens a couple of files ever, that 
does not matter too much, although I believe the process shutdown 
procudure may warn about unclosed resources.


I sometimes do this, but know what is involved. That is partly habit.


With the many files I have to process, I find the with statements
create a visual structure that is helpful to track how many files
I'm working with at once.


If processing a directory of thousands of files, I would definitely use 
the with statement.



The existence of the context also usually forces me to think more
carefully about how long I really need that resource.


It definitely makes it easier to find file opens in the code, should you 
wish to revise. There is also an aesthetic quality to cleanly closing 
things as soon as possible.



But maybe I'm being a bit zeallous.


The stdlib test code has become zealous on this and other issues as it 
is intended to be usable by all conforming implementations. We need more 
zealous people like you to help with tests (and other code) ;-).


So I would stick with your style.

--
Terry Jan Reedy

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


Re: ActivePython: multiple versions on OSX?

2011-07-26 Thread Ned Deily
In article 
,
 Melton Low  wrote:
[...]
> On Mac OS X, a link is automatically installed in /usr/local/bin for each
> version of the Python executables, ie python2.7 for the 2.7.x  and python3.2
> for 3.2.x.  Just invoke your script with the appropriate Python version.
>  eg. python3.2 yourscript to run 'yourscript'.

Yes, the default action for the python.org OS X installers is to install 
the /usr/local/bin version specific links.  However, that is not a 
complete solution for managing framework versions.   The main problem is 
that, again by default, Distutils-packaged scripts are installed into 
the framework bin directory.  This means there is no ambiguity or 
conflict among the same package/script installed in different versions 
of Python - a good thing - but it also means the proper way to manage 
which Python is invoked by `python` or by `python3` (and `python2 in the 
future when PEP 394 is approved and implemented) is by ensuring the 
desired "primary" version's framework bin directory comes first on the 
shell PATH environment variable.  The python.org installers provide a 
script to do that, although somewhat crudely.

Let's say I've used the python.org 2.6, 2.7, and 3.2 installers (and 
deselected the option to automatically update the shell scripts) and 
then use Distribute to install easy_install into those instances.  There 
is also an Apple-supplied Python 2.6 and easy_install (and 
easy_install-2.6) in /usr/bin.

$ curl -O http://python-distribute.org/distribute_setup.py
$/usr/local/bin/python2.6 distribute_setup.py
$/usr/local/bin/python2.7 distribute_setup.py
$/usr/local/bin/python3.2 distribute_setup.py
$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
$ which python python2.6 python2.7
/usr/bin/python
/usr/bin/python2.6
/usr/local/bin/python2.7
$ which easy_install easy_install-2.6 easy_install-2.7
/usr/bin/easy_install
/usr/bin/easy_install-2.6
# note that there is no access to the easy_install-2.7
#nor to the correct easy_install-2.6 for the python.org 2.6

$ open /Applications/Python\ 2.6/Update\ Shell\ Profile.command
$ bash -l
$ echo $PATH
/Library/Frameworks/Python.framework/Versions/2.6/bin:/usr/bin:/bin:/usr/
sbin:/sbin:/usr/local/bin:/usr/X11/bin
$ which python python2.6 python2.7
/Library/Frameworks/Python.framework/Versions/2.6/bin/python
/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
/usr/local/bin/python2.7
$ which easy_install easy_install-2.6 easy_install-2.7
/Library/Frameworks/Python.framework/Versions/2.6/bin/easy_install
/Library/Frameworks/Python.framework/Versions/2.6/bin/easy_install-2.6

$ open /Applications/Python\ 2.7/Update\ Shell\ Profile.command
$ bash -l
$ echo $PATH
/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks
/Python.framework/Versions/2.6/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/loc
al/bin:/usr/X11/bin
$ which python python2.6 python2.7
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
$ which easy_install easy_install-2.6 easy_install-2.7
/Library/Frameworks/Python.framework/Versions/2.7/bin/easy_install
/Library/Frameworks/Python.framework/Versions/2.6/bin/easy_install-2.6
/Library/Frameworks/Python.framework/Versions/2.7/bin/easy_install-2.7

# Now "easy_install" refers to the 2.7 version just as "python" does.

Python 3 instances work similarly although, since Apple does not yet 
ship a system Python 3, there is no conflict with /usr/bin and the 
Python 3 framework bin directories include "python3" links instead of 
"python" ones, so there is also no conflict with Python 2 instances.

$ open /Applications/Python\ 3.2/Update\ Shell\ Profile.command
$ bash -l
$ echo $PATH
/Library/Frameworks/Python.framework/Versions/3.2/bin:/Library/Frameworks
/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/V
ersions/2.6/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
$ which python python2.6 python2.7 python3 python3.2
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
/Library/Frameworks/Python.framework/Versions/3.2/bin/python3
/Library/Frameworks/Python.framework/Versions/3.2/bin/python3.2
$ which easy_install easy_install-2.6 easy_install-2.7 easy_install-3.2
/Library/Frameworks/Python.framework/Versions/3.2/bin/easy_install
/Library/Frameworks/Python.framework/Versions/2.6/bin/easy_install-2.6
/Library/Frameworks/Python.framework/Versions/2.7/bin/easy_install-2.7
/Library/Frameworks/Python.framework/Versions/3.2/bin/easy_install-3.2

But here is a potential gotcha!  Distribute does not provide a 
"easy_install3" link when installing into a Python 3 instance so now the 
unversioned "easy_install" command refers to the Python 3.2 version, 
which may not be what you expected.  You can c

Re: ActivePython: multiple versions on OSX?

2011-07-26 Thread Mark Curphey
Why not use Virtualenv ? http://pypi.python.org/pypi/virtualenv

On Mon, Jul 25, 2011 at 5:18 PM, Robert  wrote:

> Is it possible to install the 2 and 3 series side by side?
>
> --
> Robert
>
>
> --
> http://mail.python.org/**mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Only Bytecode, No .py Files

2011-07-26 Thread Dan Stromberg
Another possibility: You could probably create a bunch of zero-length .py's
that are older than the corresponding .pyc's.

On Tue, Jul 26, 2011 at 8:19 AM, Eldon Ziegler wrote:

> Is there a way to have the Python processor look only for bytecode
> files, not .py files? We are seeing huge numbers of Linux audit messages
> on production system on which only bytecode files are stored. The audit
> subsystem is recording each open failure.
>
> Thanks,
> Eldon Ziegler
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Selecting unique values

2011-07-26 Thread Dan Stromberg
Some good stuff has already been suggested.  Another possibility is using a
treap (not a duptreap but a treap):

http://stromberg.dnsalias.org/~dstromberg/treap/

If you just need things unique'd once, the set + yield is an excellent
option.  If you need to keep things in order, but also need to make changes
now and then, the treap is very good.

On Mon, Jul 25, 2011 at 3:03 PM, Kumar Mainali  wrote:

> Greetings
>
> I have a dataset with occurrence records of multiple species. I need to get
> rid of multiple listings of the same occurrence point for a species (as you
> see below in red and blue typeface). How do I create a dataset only with
> unique set of longitude and latitude for each species? Thanks in advance.
>
> Species_name Longitude Latitude
> Abies concolor -106.601 35.868
> Abies concolor -106.493 35.9682
> Abies concolor -106.489 35.892
> Abies concolor -106.496 35.8542
> Accipiter cooperi -119.688 34.4339
> Accipiter cooperi -119.792 34.5069
> Accipiter cooperi -118.797 34.2581
> Accipiter cooperi -77.38333 39.68333
> Accipiter cooperi -77.38333 39.68333
> Accipiter cooperi -75.99153 40.65
> Accipiter cooperi -75.99153 40.65
>
> - Kumar
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Only Bytecode, No .py Files

2011-07-26 Thread Eldon Ziegler
That seemed like a good idea but the .py file was complied even though
it was dated 2001-01-01 00:00:00. Python must be checking something
beside the date.


On Tue, 2011-07-26 at 12:32 -0700, Dan Stromberg wrote:
> 
> Another possibility: You could probably create a bunch of
> zero-length .py's that are older than the corresponding .pyc's.
> 
> On Tue, Jul 26, 2011 at 8:19 AM, Eldon Ziegler 
> wrote:
> Is there a way to have the Python processor look only for
> bytecode
> files, not .py files? We are seeing huge numbers of Linux
> audit messages
> on production system on which only bytecode files are stored.
> The audit
> subsystem is recording each open failure.
> 
> Thanks,
> Eldon Ziegler
> 
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


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


Re: Only Bytecode, No .py Files

2011-07-26 Thread Terry Reedy

On 7/26/2011 3:32 PM, Dan Stromberg wrote:


Another possibility: You could probably create a bunch of zero-length
.py's that are older than the corresponding .pyc's.

On Tue, Jul 26, 2011 at 8:19 AM, Eldon Ziegler mailto:eld...@atlanticdb.com>> wrote:

Is there a way to have the Python processor look only for bytecode
files, not .py files? We are seeing huge numbers of Linux audit messages
on production system on which only bytecode files are stored. The audit
subsystem is recording each open failure.


Try packaging the app into a zip file so there is only one open, which 
succeeds.


--
Terry Jan Reedy

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


Re: Only Bytecode, No .py Files

2011-07-26 Thread Christian Heimes
Am 26.07.2011 23:20, schrieb Eldon Ziegler:
> That seemed like a good idea but the .py file was complied even though
> it was dated 2001-01-01 00:00:00. Python must be checking something
> beside the date.

The first four bytes of a pyc file contain the magic header. It must
match the magic of the current Python version. The next four bytes
contain the pyc_mtime. It must match the mtime of the corresponding .py
files as returned by fstat().st_mtime. If the magic doesn't match or the
mtime header doesn't match the mtime of the .py file, the pyc is ignored.

Hint: If you run python with the -v option, you can get information why
a pyc file is ignored.

$ touch test.py
$ pycompile test.py
$ python -v -c "import test"
...
# test.pyc matches test.py
import test # precompiled from test.pyc
...
$ touch test.py
$ python -v -c "import test"
...
# test.pyc has bad mtime
import test # from test.py
...

Christian

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


Re: XRC and AGW

2011-07-26 Thread Ian Kelly
On Tue, Jul 26, 2011 at 4:16 PM, azrael  wrote:
> Is there a support in the XRC for building advaced graphics widgets (AGW).

Yes, create an "unknown" control in the XRC and then use the
xrc.AttachUnknownControl method at runtime to swap in whatever widget
you want.

> also another thing. Is ther some sort of module that make it easy to make it 
> easy to make a XRC builder easy. you know, that takes a bit care of the 
> semantics of the xml file

I use xrced, which installs with the wxPython docs and demos.  I
believe that wxFormBuilder can also generate xrc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tree structure

2011-07-26 Thread Bevan Jenkins
On Jul 26, 8:46 pm, Peter Otten <__pete...@web.de> wrote:
> Bevan Jenkins wrote:
> > Hello,
>
> > I am trying to create a tree structure for use with a PyQt QTreeView.
> > But first I need to get my head around how to create the tree
> > structure.  I have a dictionary (for testing purposes) but I will
> > later use a table via sqlalchemy.
>> SNIP<<
> > Any thoughts about how to acomplish this will be much appreciated,
> > Bevan
>
> If you turn the values into lists you can use the same function for both
> trees:
>
> INDENT = " " * 4
>
> def print_tree(lookup, node=None):
>     def _tree(node, level):
>         print "%s%s" % (INDENT * level, node)
>         for node in lookup.get(node, ()):
>             _tree(node, level+1)
>
>     if node is None:
>         for node in lookup:
>             _tree(node, 0)
>     else:
>         _tree(node, 0)
>
> def reversed_dict(tree):
>     reversed_tree = {}
>     for key, values in rivers.iteritems():
>         for value in values:
>             reversed_tree.setdefault(value, []).append(key)
>     return reversed_tree
>
> if __name__ == "__main__":
>     rivers = {
>         "little stream": "sea",
>         "mountain stream": "lake",
>         "lake": "big river",
>         "cold spring": "big river",
>         "big river": "sea",
>         "see": ""}
>
>     rivers = dict((k, [v]) for k, v in rivers.iteritems() if v)
>     print_tree(rivers)
>     print "---"
>     print_tree(reversed_dict(rivers), "sea")- Hide quoted text -
>
> - Show quoted text -

Peter,
Thank you that does what I need!  Now I just need to incorporate into
PyQt but that shouldn't be too hard...

Macro,
I need to look into lxml in the coming months, so I might revisit this
then.
-- 
http://mail.python.org/mailman/listinfo/python-list


problem in compiling C API in mingw

2011-07-26 Thread llwaeva

Hi all again, 
  I wonder if so far only Python 2.5.x support c extension. I try the
MSVC 2010 and 2008, also try mingw (gcc 4.x.x) and swig. But even I try
the simplest example, it said 

example_wrap.o:example_wrap.c:(.text+0x10ac): undefined reference to 
`_imp__PyObject_Free'
example_wrap.o:example_wrap.c:(.text+0x10f5): undefined reference to 
`_imp__PyCapsule_Import'
example_wrap.o:example_wrap.c:(.text+0x1100): undefined reference to 
`_imp__PyErr_Occurred'
example_wrap.o:example_wrap.c:(.text+0x110e): undefined reference to 
`_imp__PyErr_Clear'
example_wrap.o:example_wrap.c:(.text+0x1125): undefined reference to 
`_imp__PyImport_AddModule'
example_wrap.o:example_wrap.c:(.text+0x1144): undefined reference to 
`_imp__PyCapsule_New'
example_wrap.o:example_wrap.c:(.text+0x1165): undefined reference to 
`_imp__PyModule_AddObject'
example_wrap.o:example_wrap.c:(.text+0x1170): undefined reference to 
`_imp__PyBaseObject_Type'
example_wrap.o:example_wrap.c:(.text+0x11b2): undefined reference to 
`_imp__PyObject_SetAttr'
example_wrap.o:example_wrap.c:(.rdata+0x1e8): undefined reference to 
`PyObject_GenericGetAttr'
collect2: ld returned 1 exit status

and some sort like that.

So I try to use the compiler itself and get rid of all 3rd part tool,
here is what I did

/ source code
#include "Python.h"

static  PyObject *
ex_foo(PyObject *self, PyObject *args)
{
printf("Hello, world n " );
Py_INCREF(Py_None);
return  Py_None;
}

static  PyMethodDef example_methods[] = {
{"foo" , ex_foo, METH_VARARGS, "foo() doc string" },
{NULL , NULL }
};

static  struct  PyModuleDef examplemodule = {
PyModuleDef_HEAD_INIT,
"example" ,
"example module doc string" ,
-1 ,
example_methods,
NULL ,
NULL ,
NULL ,
NULL
};

PyMODINIT_FUNC
PyInit_example(void )
{
return  PyModule_Create(&examplemodule);
}

/// my setup.py
from distutils.core import setup, Extension

module1 = Extension('example', sources = ['example.c'])

setup (name = 'example', version = '1.0', description = 'This is a demo 
package', ext_modules = [module1])


// running
python setup.py build --compiler=mingw32


$ python setup.py build --compiler=mingw32
running build
running build_ext
building 'example' extension
D:\Programs\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-Ic:\Program Files (x8
6)\Python\include" "-Ic:\Program Files (x86)\Python\PC" -c example.c -o build\te
mp.win-amd64-3.1\Release\example.o
writing build\temp.win-amd64-3.1\Release\example.def
D:\Programs\MinGW\bin\gcc.exe -mno-cygwin -shared -s build\temp.win-amd64-3.1\Re
lease\example.o build\temp.win-amd64-3.1\Release\example.def "-Lc:\Program Files
 (x86)\Python\libs" "-Lc:\Program Files (x86)\Python\PCbuild\amd64" -lpython31 -
lmsvcr90 -o build\lib.win-amd64-3.1\example.pyd
build\temp.win-amd64-3.1\Release\example.o:example.c:(.text+0x13): undefined ref
erence to `_imp___Py_NoneStruct'
build\temp.win-amd64-3.1\Release\example.o:example.c:(.text+0x32): undefined ref
erence to `_imp__PyModule_Create2'
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
- Original Message Ends 



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


@PyNoobs: The Fundamental Five Built-in Functions, and Beyond!

2011-07-26 Thread rantingrick



 The "Fundamental Five" built-in functions

There are quite a few helpful built in functions provided to the
python programmer however in my mind five of them are the most
important to Python noobs. The "fundamental five" i call them. I
believe you should not do anything with Python until you are
completely familier with these five because most of the bugs and mis-
understanding a new user experiences can be solved by using these five
functions.


--
1. help()
--
http://docs.python.org/py3k/library/functions.html#help

The "help" function is by far the most important of all Python built
in functions. It is a gift handed down from the gods who reside at py-
dev so don't balk at it or you'll suffer plagues of exceptions. Unlike
other languages, Python has documentation built-in in the form of
docstrings and the help function will pull out as much or as little
info as you'd like from these do strings. No need to carry around
heavy books or hundreds of links to www tuts because everything you
need to know (reference wise) is available via the help function. Run
the help function and ye shall be enlightened!

--
 2. dir()
--
http://docs.python.org/py3k/library/functions.html#dir

Python has name spaces. Name spaces are awesome. Name spaces keep code
from clashing with other code. The dir() function will list the
currently defined names in the current namespace. If your getting
NameErrors check the name space with dir() function.

--
 3. repr()
--
http://docs.python.org/py3k/library/functions.html#repr

Most new user think that printing an object to stdout is all they'll
ever need. However when you call print -- or sys.stdout.write(object)
-- you are only seeing a "friendly" version of the object. You can
even control the return value in your own classes bu overriding the
obj.__str__() special method. This friendly version is sufficient most
of the time HOWEVER when debugging it can lead you to smash you head
on the keyboard repeatedly due to it's sometimes misleading nature. If
you need to get the true "representation" of an object then call...
repr(object).

--
 4. type()
--
http://docs.python.org/py3k/library/functions.html#isinstance

Ever had a TypeError? Ever had some object you were just sure was one
type but is not behaving like that type? Then check it's type for
Pete's sake! Even experienced programmers (of many languages) suffer
from TypeErrors (be them subtle or not) because the type of an object
cannot be inferred simply by looking at it's identifier. So when
something ain't right, skip the tripe, and check the type!

--
 5. id()
--
http://docs.python.org/py3k/library/functions.html#id

Ah yes, another source of frustration is the old "identical twin"
syndrome (or in the worst forms; multiplicity syndrome!). Yes, on the
surface that list of lists looks as if it contains unique elements
HOWEVER you keep getting strange results. How are you going to find
the problem? Hmm? Never fear my confused new friend, by comparing the
ids of two objects you can know if they are actually the same or
different. If the id is the same, the objects are the same.

--
Summary
--
These five functions are vital to debugging any python code or
understanding an API. You will be using these functions over and over
again, so the sooner you learn them the better!

==
 Extending "The Five"
==
Once you have mastered the five it is time to expand your horizons a
bit. The next group of functions will complete the circle of
introspection.
==
 * hasattr()
 * isintance()
 * issubclass()
 * callable()
 * super()
 * vars()
 * globals()
 * locals()

 * ascii()

==
General Built-in Functions by Group.
==

--
 Objects
--
Bulling an object:
 * delattr()
 * getattr()
 * setattr()

Setting the rules:
 * staticmethod()
 * classmethod()
 * property()

--
 Numbers and Math
--

seeking an example on C extension works in python 3.1.x or above

2011-07-26 Thread llwaeva
Hello,
  I have been searching the example on C extension that works in python
3.1.x ror above for long time. I tried the simple example given in
python document or enclosed in python's src (PC folder), doesn't work,

undefined reference to  `_imp___Py_NoneStruct'

and
undefined reference to  `_imp__PyModule_Create2'

error caught. For the first one, somewhere it could be fixed by some way
mentioned in the faq somewhere. But I don't see any suggestion in the
internet or in the mail list about that. Can any one who ever succeed to  
compile
the any example to extend python (3.1 +) with C API under windows?

I am using windows 64bit + VC2010 and gcc  mingw.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem in compiling C API in mingw

2011-07-26 Thread Thomas Jollans
On 27/07/11 01:53, llwa...@gmail.com wrote:
> 
> $ python setup.py build --compiler=mingw32
> running build
> running build_ext
> building 'example' extension
> D:\Programs\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-Ic:\Program Files 
> (x8
> 6)\Python\include" "-Ic:\Program Files (x86)\Python\PC" -c example.c -o 
> build\te
> mp.win-amd64-3.1\Release\example.o
> writing build\temp.win-amd64-3.1\Release\example.def
> D:\Programs\MinGW\bin\gcc.exe -mno-cygwin -shared -s 
> build\temp.win-amd64-3.1\Re
> lease\example.o build\temp.win-amd64-3.1\Release\example.def "-Lc:\Program 
> Files
>  (x86)\Python\libs" "-Lc:\Program Files (x86)\Python\PCbuild\amd64" 
> -lpython31 -
> lmsvcr90 -o build\lib.win-amd64-3.1\example.pyd
> build\temp.win-amd64-3.1\Release\example.o:example.c:(.text+0x13): undefined 
> ref
> erence to `_imp___Py_NoneStruct'
> build\temp.win-amd64-3.1\Release\example.o:example.c:(.text+0x32): undefined 
> ref
> erence to `_imp__PyModule_Create2'
> collect2: ld returned 1 exit status
> error: command 'gcc' failed with exit status 1
> - Original Message Ends 

Curious. You appear to be using a 32-bit C compiler (mingw32), and
Python appears to be installed in "Program Files (x86)", suggesting a
32-bit version, but distutils appears to generate directory names of the
format "XXX.win-amd64-3.1" - suggesting some kind of architecture
conflict. Then again, I remember some bug about Python reporting the
wrong architecture on Windows, so this could just be a fluke, but if
your extension and Python were built for different architectures that
would explain it.

So the best advice I can offer at this point is: install Python 3.2, and
make sure that either (a) you use a 64-bit compiler (and Python), or (b)
you use a 32-bit Python (and compiler).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strings show as brackets with a 'u'.

2011-07-26 Thread rantingrick
On Jul 25, 3:00 am, Ulrich Eckhardt 
wrote:
> Chris Angelico wrote:
>
> > [snip]
>
> You just gave the OP a fish, he provided a
> valuable advise on fishing itself.

I always believed the best way to teach someone is not to give them a
direct answer. No. Instead i like to offer clues so that the person
can utilize his own problem solving skills to find the answer. Because
the most important skill a person can have in the programming field is
the ability to solve complex problems by breaking them down into their
smallest units; tackling each unit; and finally assembling the puzzle
in a cohesive and intelligent manner.

Anyway the OP may want to check out my recent thread regarding
Python's Built-in Functions.
http://groups.google.com/group/comp.lang.python/browse_thread/thread/f419d4e11f27882e?hl=en#

--
rr
http://sites.google.com/site/thefutureofpython/

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


Re: @PyNoobs: The Fundamental Five Built-in Functions, and Beyond!

2011-07-26 Thread Thomas Jollans
Beyond!

On 27/07/11 02:01, rantingrick wrote:
> --
> 1. help()
> --
> --
>  2. dir()
> --

Pro tip: the "IPython" enhanced Python shell makes these two even more
amicable.

> --
>  3. repr()
> --
> http://docs.python.org/py3k/library/functions.html#repr
> 
> Most new user think that printing an object to stdout is all they'll
> ever need. 

Also handy: the "pprint" stdlib module to pretty-print complex structures.

http://docs.python.org/py3k/library/pprint.html

> --
>  5. id()
> --

This reminds me of something I did last year. Some of you might recall.
http://blog.jollybox.de/archives/62-python-swap
(Word of warning: bad idea. Very, very bad idea. Still, potentially
amusing. Kind of like blowing up a giant hydrogen-filled baloon.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 8 and extraneous whitespace

2011-07-26 Thread Steven D'Aprano
AlienBaby wrote:

>> (on limiting line lengths)..
> 
> I didn't see this mentioned;
> 
> I have a hard time keeping python code limited to 80 char line lengths
> _because_ indentation is significant, 

Are you suggesting that if indentation was not significant, you wouldn't
write such long lines? *wink*

Whether significant or not, the fact that it is there at all is what
matters.

> and can end up consuming quite a lot of linespace itself.

If you are using 8 space indents, do yourself, and your readers, a favour
and change to 4 spaces.

If you regularly have more than four or five nested indents, I would
seriously advise you to refactor your code into a flatter structure. I've
done a quick (and unscientific) survey of my code, and roughly 80% of it is
between 1 and 3 indents (inclusive). Only a tiny portion reaches 6 indents.
If I've ever gone to 7, and I can't find it with a quick random survey.


> Couple that with a liking for 
> long_memorable_explanatory_names, and an 80 char limit causes (me)
> problems.

Names can be too long as well as too short. If you are a carpenter, you
surely wouldn't bang nails with a
metal_manually_operated_hammering_device_with_nail_removing_attachment, you
would use a hammer.

But even with long names, if you are *regularly* going over 80 characters,
you may be doing something wrong. 80 characters is a lot -- most of my
lines of code are under 50, including indentation. I haven't seen your
code, so I could be way off base here, but I expect you're using deeply
hierarchical data structures, and violating the Law of Demeter:

paper = paper_boy.give_newspaper()
# Pay the paper boy.
paper_boy.collect_payment(customer.backpocket.wallet(2.0, tip=300.00))

Don't let the paper boy reach into your wallet and pay himself!



-- 
Steven

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


Re: seeking an example on C extension works in python 3.1.x or above

2011-07-26 Thread Dan Stromberg
You could try looking in the Python sources for examples.

But using Cython is probably easier.

On Tue, Jul 26, 2011 at 5:06 PM,  wrote:

> Hello,
>  I have been searching the example on C extension that works in python
> 3.1.x ror above for long time. I tried the simple example given in
> python document or enclosed in python's src (PC folder), doesn't work,
>
> undefined reference to  `_imp___Py_NoneStruct'
>
> and
> undefined reference to  `_imp__PyModule_Create2'
>
> error caught. For the first one, somewhere it could be fixed by some way
> mentioned in the faq somewhere. But I don't see any suggestion in the
> internet or in the mail list about that. Can any one who ever succeed to
>  compile
> the any example to extend python (3.1 +) with C API under windows?
>
> I am using windows 64bit + VC2010 and gcc  mingw.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-26 Thread John Salerno
On Jul 9, 9:01 pm, John Salerno  wrote:
> Thanks everyone! I probably should have said something like "Python,
> if possible and efficient, otherwise any other method" ! :)
>
> I'll look into the Task Scheduler. Thanks again!

Hmm, okay I'm finally trying Task Scheduler, but how do I set it to
run a Python script? It seems to not work, I suppose because it's
running the script but doesn't know how to find Python to run it
properly.

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


Re: seeking an example on C extension works in python 3.1.x or above

2011-07-26 Thread Dan Stromberg
BTW, I believe you need to compile your extension module(s) with the same
compiler that was used to build the Python interpreter - otherwise there
could be calling convention issues.

On Tue, Jul 26, 2011 at 5:58 PM, Dan Stromberg  wrote:

>
> You could try looking in the Python sources for examples.
>
> But using Cython is probably easier.
>
>
> On Tue, Jul 26, 2011 at 5:06 PM,  wrote:
>
>> Hello,
>>  I have been searching the example on C extension that works in python
>> 3.1.x ror above for long time. I tried the simple example given in
>> python document or enclosed in python's src (PC folder), doesn't work,
>>
>> undefined reference to  `_imp___Py_NoneStruct'
>>
>> and
>> undefined reference to  `_imp__PyModule_Create2'
>>
>> error caught. For the first one, somewhere it could be fixed by some way
>> mentioned in the faq somewhere. But I don't see any suggestion in the
>> internet or in the mail list about that. Can any one who ever succeed to
>>  compile
>> the any example to extend python (3.1 +) with C API under windows?
>>
>> I am using windows 64bit + VC2010 and gcc  mingw.
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Selecting unique values

2011-07-26 Thread Kumar Mainali
Thank you everybody. I can extract unique values now.

- Kumar

On Tue, Jul 26, 2011 at 2:38 PM, Dan Stromberg  wrote:

>
> Some good stuff has already been suggested.  Another possibility is using a
> treap (not a duptreap but a treap):
>
> http://stromberg.dnsalias.org/~dstromberg/treap/
>
> If you just need things unique'd once, the set + yield is an excellent
> option.  If you need to keep things in order, but also need to make changes
> now and then, the treap is very good.
>
>  On Mon, Jul 25, 2011 at 3:03 PM, Kumar Mainali wrote:
>
>>  Greetings
>>
>> I have a dataset with occurrence records of multiple species. I need to
>> get rid of multiple listings of the same occurrence point for a species (as
>> you see below in red and blue typeface). How do I create a dataset only with
>> unique set of longitude and latitude for each species? Thanks in advance.
>>
>> Species_name Longitude Latitude
>> Abies concolor -106.601 35.868
>> Abies concolor -106.493 35.9682
>> Abies concolor -106.489 35.892
>> Abies concolor -106.496 35.8542
>> Accipiter cooperi -119.688 34.4339
>> Accipiter cooperi -119.792 34.5069
>> Accipiter cooperi -118.797 34.2581
>> Accipiter cooperi -77.38333 39.68333
>> Accipiter cooperi -77.38333 39.68333
>> Accipiter cooperi -75.99153 40.65
>> Accipiter cooperi -75.99153 40.65
>>
>> - Kumar
>>
>> --
>>
>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Only Bytecode, No .py Files

2011-07-26 Thread harrismh777

Christian Heimes wrote:

The first four bytes of a pyc file contain the magic header. It must
match the magic of the current Python version. The next four bytes
contain the pyc_mtime. It must match the mtime of the corresponding .py
files as returned by fstat().st_mtime. If the magic doesn't match or the
mtime header doesn't match the mtime of the .py file, the pyc is ignored.


   ... so recompile is required to fix.



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


Re: Strings show as brackets with a 'u'.

2011-07-26 Thread goldtech
Thank you. So what is happening? Is it that I'm in an environment that
is not unicode and python is telling me the string (ie. n[0]) is
unicode? (I'll do a hatchet-job on this subject if I ask anymore about
unicode). Thanks to posters for their patience!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-26 Thread Ethan Furman

John Salerno wrote:

On Jul 9, 9:01 pm, John Salerno  wrote:

Thanks everyone! I probably should have said something like "Python,
if possible and efficient, otherwise any other method" ! :)

I'll look into the Task Scheduler. Thanks again!


Hmm, okay I'm finally trying Task Scheduler, but how do I set it to
run a Python script? It seems to not work, I suppose because it's
running the script but doesn't know how to find Python to run it
properly.


You need to have Python be the command, then add the script as the 
parameter (you may need to right-click and go to properties... or 
something like that ;) .


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


Re: How can I make a program automatically run once per day?

2011-07-26 Thread Andrew Berg
On 2011.07.26 08:05 PM, John Salerno wrote:
> Hmm, okay I'm finally trying Task Scheduler, but how do I set it to
> run a Python script? It seems to not work, I suppose because it's
> running the script but doesn't know how to find Python to run it
> properly.
Tell it to run the Python interpreter and pass the script as an argument.

-- 
CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0
PGP/GPG Public Key ID: 0xF88E034060A78FCB
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: @PyNoobs: The Fundamental Five Built-in Functions, and Beyond!

2011-07-26 Thread Steven D'Aprano
On Wed, 27 Jul 2011 10:01 am rantingrick wrote:

> 
>  The "Fundamental Five" built-in functions
> 
> There are quite a few helpful built in functions provided to the
> python programmer however in my mind five of them are the most
> important to Python noobs. The "fundamental five" i call them. I
> believe you should not do anything with Python until you are
> completely familier with these five because most of the bugs and mis-
> understanding a new user experiences can be solved by using these five
> functions.

Rick, this is excellent work. If you did more of this sort of thing and less
ranting, you would be far more respected and much less likely to be
kill-filed.

You've just earned yourself a retroactive Get Out Of Kill-File card. Don't
make me regret it.



-- 
Steven

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


Re: @PyNoobs: The Fundamental Five Built-in Functions, and Beyond!

2011-07-26 Thread Terry Reedy

On 7/26/2011 8:01 PM, rantingrick wrote:




  The "Fundamental Five" built-in functions

There are quite a few helpful built in functions provided to the
python programmer however in my mind five of them are the most
important to Python noobs. The "fundamental five" i call them. I
believe you should not do anything with Python until you are
completely familier with these five because most of the bugs and mis-
understanding a new user experiences can be solved by using these five
functions.


--
1. help()
--
http://docs.python.org/py3k/library/functions.html#help


help() with no args puts one into a special help mode to get info on 
various topics. help(obj) gets help on that object. I do not do the 
former much, but I increasingly use the latter.




--
  2. dir()
--
http://docs.python.org/py3k/library/functions.html#dir

Python has name spaces. Name spaces are awesome. Name spaces keep code
from clashing with other code. The dir() function will list the
currently defined names in the current namespace. If your getting
NameErrors check the name space with dir() function.


I use this constantly.


--
  3. repr()
--
http://docs.python.org/py3k/library/functions.html#repr

Most new user think that printing an object to stdout is all they'll
ever need. However when you call print -- or sys.stdout.write(object)
-- you are only seeing a "friendly" version of the object.


This mostly applies to strings, which *do* have 2 printed versions.  It 
is occasionally very important for debugging string problems.


Printing collections alreays used repr() for members of the collection.



--
  4. type()
--
http://docs.python.org/py3k/library/functions.html#isinstance

Ever had a TypeError? Ever had some object you were just sure was one
type but is not behaving like that type? Then check it's type for
Pete's sake! Even experienced programmers (of many languages) suffer
from TypeErrors (be them subtle or not) because the type of an object
cannot be inferred simply by looking at it's identifier. So when
something ain't right, skip the tripe, and check the type!

--
  5. id()
--
http://docs.python.org/py3k/library/functions.html#id

Ah yes, another source of frustration is the old "identical twin"
syndrome (or in the worst forms; multiplicity syndrome!). Yes, on the
surface that list of lists looks as if it contains unique elements
HOWEVER you keep getting strange results. How are you going to find
the problem? Hmm? Never fear my confused new friend, by comparing the
ids of two objects you can know if they are actually the same or
different. If the id is the same, the objects are the same.


This is the most dangerous of the builtins, as it sometimes mislead 
newbies into 'discovering' non-existent 'bugs'. The main point is that 
the id of immutable objects is mostly an irrelevant implementation 
detail, while the id of mutables may be critical. Lists of lists is a 
particular area where id() is really useful.


--
Terry Jan Reedy

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


Re: seeking an example on C extension works in python 3.1.x or above

2011-07-26 Thread Terry Reedy

On 7/26/2011 8:06 PM, llwa...@gmail.com wrote:

Hello,
   I have been searching the example on C extension that works in python
3.1.x


All the stdlib modules written in C. These are extension modules that 
come with Python. There are perhaps a hundred more on PyPI.



Can any one who ever succeed to  compile
the any example to extend python (3.1 +) with C API under windows?
I am using windows 64bit + VC2010 and gcc  mingw.


Use VC2008. Mingw is problematical, though it has been done, I believe 
not trying to pass open files between vc code and gcc code is one 
requirement, as the stdio layouts are different.


--
Terry Jan Reedy

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


Re: Strings show as brackets with a 'u'.

2011-07-26 Thread Terry Reedy

On 7/26/2011 9:18 PM, goldtech wrote:

Thank you. So what is happening? Is it that I'm in an environment that
is not unicode and python is telling me the string (ie. n[0]) is
unicode?


Yes, n is a list and n[0] is a unicode string and you are using some 
2.x, which is ascii/byte string based. Python 3 is unicode based.


If you do not *need* to use 2.x and are just learning Python, I 
personally recommend starting with Python 3. Others agree with me, still 
other do not. I would add 'especially if you want to use unicode'.


Rick gave you some good advice, perhaps worth re-reading. What you need 
are investigative skills, and not just bits of data.


--
Terry Jan Reedy

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


Re: How can I make a program automatically run once per day?

2011-07-26 Thread John Salerno
On Jul 26, 9:22 pm, Andrew Berg  wrote:
> On 2011.07.26 08:05 PM,JohnSalernowrote:> Hmm, okay I'm finally trying Task 
> Scheduler, but how do I set it to
> > run a Python script? It seems to not work, I suppose because it's
> > running the script but doesn't know how to find Python to run it
> > properly.
>
> Tell it to run the Python interpreter and pass the script as an argument.
>
> --
> CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0
> PGP/GPG Public Key ID: 0xF88E034060A78FCB

Thank you. I changed it as suggested so that now it runs C:
\Python32\python.exe extract_songs.py but it still isn't working. A
DOS prompt flashes real quick as it runs, but when I check the output
file that is supposed to be written to, nothing new has been added.
I'm not sure what the problem is now. I know the script itself works
because I just ran it manually and the output was fine.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strings show as brackets with a 'u'.

2011-07-26 Thread Steven D'Aprano
On Wed, 27 Jul 2011 11:18 am goldtech wrote:

> Thank you. So what is happening? Is it that I'm in an environment that
> is not unicode and python is telling me the string (ie. n[0]) is
> unicode? (I'll do a hatchet-job on this subject if I ask anymore about
> unicode). Thanks to posters for their patience!

It's hard to say with no context remaining. I take it you're printing n[0]
and getting unexpected results?

To start with, try calling this: type(n[0])

That will tell you if the object is a byte-string, or unicode.

I don't think there is any way to tell the console's encoding directly from
Python, although you can look at sys.stdout.encoding which will tell you
what Python thinks it is.

I think that from Windows you can run chcp.exe to see the console encoding,
although I can't confirm that. From Linux, there's probably a bazillion
different ways, none of which guaranteed to be either correct or consistent
with the others. But I'm not bitter.

You can try with the default locale encoding, or the LANG environment
variable:

locale charmap
echo $LANG

but that only tells you what your shell thinks the encoding should be, not
what your terminal is actually using.

Your console app (xterm, konsole, Gnome terminal, whatever...) probably has
a way to query what encoding it is using, but I'll be buggered if I can
find out what that is. In konsole I can look at the Settings > Encodings
menu, but it claims to be using "default". How very useful.



-- 
Steven

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


Re: ActivePython: multiple versions on OSX?

2011-07-26 Thread Sridhar Ratnakumar
On Mon, Jul 25, 2011 at 5:18 PM, Robert  wrote:
> Is it possible to install the 2 and 3 series side by side?
>

Yup.

Moreover, ActivePython includes a tool called `pythonselect` that can
be used to set the "current" version of Python,
https://github.com/ActiveState/pythonselect#readme

For OSX, this basically sets symlinks in /usr/local/bin targeting the
appropriate Framework location.

The included pip and easy_install scripts are versioned, eg: pip-2.7
and pip-3.2.

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


Re: How can I make a program automatically run once per day?

2011-07-26 Thread Chris Angelico
On Wed, Jul 27, 2011 at 2:09 PM, John Salerno  wrote:
> Thank you. I changed it as suggested so that now it runs C:
> \Python32\python.exe extract_songs.py but it still isn't working.

Have you confirmed that the job's working directory is set correctly?
Naming the script without a path depends on the task being run from
the script's directory.

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