SQLObject 0.12.0

2009-10-21 Thread Oleg Broytman
Hello!

I'm pleased to announce version 0.12.0, the first stable release of
branch 0.12 of SQLObject.


What is SQLObject
=

SQLObject is an object-relational mapper.  Your database tables are described
as classes, and rows are instances of those classes.  SQLObject is meant to be
easy to use and quick to get started with.

SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite,
Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB).


Where is SQLObject
==

Site:
http://sqlobject.org

Development:
http://sqlobject.org/devel/

Mailing list:
https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss

Archives:
http://news.gmane.org/gmane.comp.python.sqlobject

Download:
http://cheeseshop.python.org/pypi/SQLObject/0.12.0

News and changes:
http://sqlobject.org/News.html


What's New
==

Features  Interface


* .selectBy(), .deleteBy() and .by*() methods pass all values through
  .from_python(), not only unicode.

* The user can choose a DB API driver for SQLite by using a backend
  parameter in DB URI or SQLiteConnection that can be a comma-separated
  list of backend names. Possible backends are: pysqlite2 (alias
  sqlite2), sqlite3, sqlite (alias sqlite1). Default is to test
  pysqlite2, sqlite3 and sqlite in that order.

* The user can choose a DB API driver for PostgreSQL by using a backend
  parameter in DB URI or PostgresConnection that can be a comma-separated
  list of backend names. Possible backends are: psycopg2, psycopg1,
  psycopg (tries psycopg2 and psycopg1), pygresql. Default is
  psycopg.
  WARNING: API change! PostgresConnection's parameter
  usePygresql is now replaced with backend=pygresql.

* The user can choose a DB API driver for MSSQL by using a backend
  parameter in DB URI or MSSQLConnection that can be a comma-separated list
  of backend names. Possible backends are: adodb (alias adodbapi) and
  pymssql. Default is to test adodbapi and pymssql in that order.

* alternateMethodName is defined for all unique fields, not only alternateID;
  this makes SQLObject create .by*() methods for all unique fields.

* SET client_encoding for PostgreSQL to the value of charset parameter
  in DB URI or PostgresConnection.

* TimestampCol() can be instantiated without any defaults, in this case
  default will be None (good default for TIMESTAMP columns in MySQL).

Small Features
--

* Imported DB API drivers are stored as connection instance variables, not
  in global variables; this allows to use different DB API drivers at the
  same time; for example, PySQLite2 and sqlite3.

* Removed all deprecated attribute and functions.

* Removed the last remained string exceptions.

For a more complete list, please see the news:
http://sqlobject.org/News.html

Oleg.
-- 
 Oleg Broytmanhttp://phd.pp.ru/p...@phd.pp.ru
   Programmers don't die, they just GOSUB without RETURN.
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Setuptools 0.6c11 released

2009-10-21 Thread P.J. Eby

Oops!
-

Due to a couple of last-minute issues with the 0.6c10 release, I've 
released an 0.6c11 update at:


   http://pypi.python.org/setuptools/

It fixes an error when running the sdist command on a package with 
no README, and includes the 64-bit Windows fix that was promised in 
0.6c10 but wasn't actually checked in to SVN.


You can install the updated version using easy_install (or pip!), by 
asking for setuptools==0.6c11.



The Fine Print
--

(Note for users of Distribute: Distribute and setuptools use the same 
package name 'setuptools', and thus cannot both be present on the 
same sys.path (e.g. in the same virtualenv).  If you wish to switch a 
given environment from Distribute to setuptools or vice versa, you 
will need to completely uninstall one before installing the 
other.  If you currently have Distribute installed, please follow 
Distribute's uninstall instructions if you wish to reinstall setuptools.)


Please report any bugs to the setuptools bug tracker at:

  http://bugs.python.org/setuptools/

For faster response to questions, please use the distutils-sig 
mailing list, rather than the tracker.  Setuptools documentation can 
be found via links at 
http://pypi.python.org/pypi/setuptools#using-setuptools-and-easyinstall 
-- and the pages on the PEAK wiki now load much, much faster than 
they did a few months ago.  (They're static cached pages now, rather 
than dynamically generated, unless you're actually logged into the wiki.)


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

   Support the Python Software Foundation:
   http://www.python.org/psf/donations/


Re: Frameworks

2009-10-21 Thread Emmanuel Surleau
 On Oct 20, 2009, at 4:59 PM, Emmanuel Surleau wrote:
  Compared to custom tags in, say, Mako? Having to implement a mini-
  parser for
  each single tag when you can write a stupid Python function is
  needless
  complication.
 
 I like Mako a lot and in fact web2py template took some inspiration
 from it. Here is a mako example:
 
 % for a in ['one', 'two', 'three', 'four', 'five']:
  % if a[0] == 't':
   its two or three
  % elif a[0] == 'f':
  four/five
  % else:
  ${a}
  %endif
 % endfor
 
 
 Here is the same in web2py-ese, translated line by line
 
   {{for a in ['one', 'two', 'three', 'four', 'five']:}}
  {{if a[0] == 't':}}
   its two or three
  {{elif a[0] == 'f':}}
  four/five
  {{else:}}
  {{=a}}
  {{pass}}
 {{pass}}
 
 Legend Mako - web2py
 % - {{  }}
 endif - pass
 endfor - pass
 ${...} - {{=...}}
 
 Mako introduces terms like endif, endfor which are not Python
 keywords. Web2py only uses valid python keywords.

Ingenious. Web2py looks more consistent (everything relies on {{ }} while Mako 
uses %, $ and % ). On the other hand, the Mako syntax is a bit lighter to my 
eyes. Tradeoffs, tradeoffs...
 
 Here is another example, in Mako:
 
 %def name=myfunc(x)
  this is myfunc, x is ${x}
 /%def
 ${myfunc(7)}
 
 and the same in web2py
 
 {{def myfunc(x):}}
 this is myfunc, x is {{=x}}
 {{return}}
 {{myfunc(7)}}
 
 Again web2py does not introduce any new syntax. only valid Python in
 {{...}} tags.
 (Notice {{myfunc(7)}} not {{=myfunc(7)}} becase the function is
 printing, we are not printing the return value of the function).
 
 Mako needs to parse % ..., %.../%, ... and ${...}. web2py needs to
 parse only {{...}}.
 
 The use of {{...}} in web2py is inspired by Django. This has a big
 advantage over %...%, it is transparent to html editors and so you
 use any html editor with the templates.

Bah, as if anyone needed anything else than vim :) Just joking, I see the 
advantage if you are working with external designers.

Cheers,

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


Re: help to convert c++ fonction in python

2009-10-21 Thread Paul Rudin
Gary Herron gher...@islandtraining.com writes:

 geremy condra wrote:

 And always apply ROT13 twice for extra security.
   
 +1 for quote of the week

Even if it's at least 30 years old :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a simple unicode question

2009-10-21 Thread Mark Tolonen


George Trojan george.tro...@noaa.gov wrote in message 
news:hbktk6$8b...@news.nems.noaa.gov...

Thanks for all suggestions. It took me a while to find out how to
configure my keyboard to be able to type the degree sign. I prefer to
stick with pure ASCII if possible.
Where are the literals (i.e. u'\N{DEGREE SIGN}') defined? I found
http://www.unicode.org/Public/5.1.0/ucd/UnicodeData.txt
Is that the place to look?

George

Scott David Daniels wrote:

Mark Tolonen wrote:

Is there a better way of getting the degrees?


It seems your string is UTF-8.  \xc2\xb0 is UTF-8 for DEGREE SIGN.  If 
you type non-ASCII characters in source code, make sure to declare the 
encoding the file is *actually* saved in:


# coding: utf-8

s = '''48° 13' 16.80 N'''
q = s.decode('utf-8')

# next line equivalent to previous two
q = u'''48° 13' 16.80 N'''

# couple ways to find the degrees
print int(q[:q.find(u'°')])
import re
print re.search(ur'(\d+)°',q).group(1)



Mark is right about the source, but you needn't write unicode source
to process unicode data.  Since nobody else mentioned my favorite way
of writing unicode in ASCII, try:

IDLE 2.6.3
  s = '''48\xc2\xb0 13' 16.80 N'''
  q = s.decode('utf-8')
  degrees, rest = q.split(u'\N{DEGREE SIGN}')
  print degrees
48
  print rest
 13' 16.80 N

And if you are unsure of the name to use:
  import unicodedata
  unicodedata.name(u'\xb0')
'DEGREE SIGN'


It wouldn't be your favorite way if you were typing Chinese:

x = u'我是美国人。'

vs.

x = u'\N{CJK UNIFIED IDEOGRAPH-6211}\N{CJK UNIFIED IDEOGRAPH-662F}\N{CJK 
UNIFIED IDEOGRAPH-7F8E}\N{CJK UNIFIED IDEOGRAPH-56FD}\N{CJK UNIFIED 
IDEOGRAPH-4EBA}\N{IDEOGRAPHIC FULL STOP}'


;^) Mark





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


win32com lotus notes: not opened

2009-10-21 Thread Threader Slash
Hi Everybody,

Hope someone can point me some direction...

I got python linking to lotus notes, under Eclipse IDE. The code is:

import pythoncom
import pywintypes
from win32com.client import Dispatch
session=Dispatch(Lotus.NotesSession)
session

print pythoncom.CreateGuid()

try:
session.Initialize(password)
db = session.getDatabase(local, C:\Program
Files\lotus\notes\data\mydata.nsf)

agent=db.getAgent(($All))
doc = db.CreateDocument()
view = db.GetView(($All))
doc = view.getFirstDocument()

testvar = doc.getItemValue(($All))

except pywintypes.com_error: raise

but the compiler gives me the error:

.nsf has not been opened yet

Any suggestion? Thanks. ThreaderSlash
-- 
http://mail.python.org/mailman/listinfo/python-list


mysql select some sort of caching

2009-10-21 Thread Threader Slash
-- Forwarded message --
From: David Sfiligoi sfili...@gmail.com
To: python-list@python.org
Date: Tue, 20 Oct 2009 21:41:10 -0500
Subject: mysql select some sort of caching
Hi
I am normally an SQLlite person because it just works... but I decided to
keep inproving my skills set and do my new project using a MySQL database
backend because of the architecture decision I made(horizontal scalable
system via message queues). The project is architected around a rabbitmq
system with bunch of consumers(potentially large) and publishers... I
digress, the rabbit has a no part to play in my myunderstanding with
mysql.

I have a consumer that get data from a queue(a url). This queue is
checked in a loop. Once a url has been published in the queue, the
consumer sees it and call a function to do something with it.  Using a
column in the table I verify if 'today's task' has been done already
(compare the current date to the last task date that I store in the table
last time I executed the task)

So normally I would open a connection and instentiate a cursor for my
queries once at a global level(like find out if the current date is 
than the last task date). Then go in an infinite loop that wait for data
to arrive in the queue and carry the cursor and connection over.  However
this is the issue I seem to run into.  I test the code by zapping, using
mysql query tools, the table's last task date column with an older date
so that current date is larger than the current date.  Issue is that
whatever prior date I put in the table's last task date colum somehow
they are not seen by the SELECT query
sqlcur.execute(SELECT `url`d` from `url_snapshot` WHERE `url` = %s and
`lastsnapshotdate`  %s,(url,currentdate))
that query returns old data.

Just like if the query is cachedyet the data actually changed in the
database.

However when I recreate a new connection and cursor everytime I get a new
message in the queue(url), therefore within the message found loop there
are no issues seeing the last update done via the mysql query tool

I don't think this has to do with mysql caching features since its
suppose to detect when the fields changed.

Any ideas?

Thanks for your Time,
David

-- Forwarded message --

A simple suggestion.. in your next post - go direct to your problem.

Just to be sure, did you got a commit!?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to knock a page out of file cache

2009-10-21 Thread Paul Rubin
birdsong david.birds...@gmail.com writes:
 Does anybody know of a system call that will 'knock' the file out of
 file cache?  Can madvise or fadvise do this?

I don't think so.  Best I can think of is unmount and remount the file
system.  And I don't know if even that is guaranteed if you don't
physically remove/unplug the device.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Struct on on x86_64 mac os x

2009-10-21 Thread Mark Tolonen


Tommy Grav tg...@pha.jhu.edu wrote in message 
news:d705ab12-0bee-495a-b1e5-c43245e40...@pha.jhu.edu...

I have created a binary file that saves this struct from some C code:

  struct recOneData {
 char label[3][84];
 char constName[400][6];
   double timeData[3];
 long int numConst;
   double AU;
   double EMRAT;
 long int coeffPtr[12][3];
 long int DENUM;
 long int libratPtr[3];
 };

I try to read this file with python (ActiveState 2.6.3 on x86_64 Mac  OS X 
10.6.1) using the
code below the hdrData and constNData are fine, while from the  timeData 
onwards there
are obvious problems. The code below works fine for a 32bit binary  read 
with i386 python
2.5.2. Does anyone know what the proper format of a C double and long  int 
is for a x86_64

binary?

def read_header(cls):
hdrData = 84s*3
constNData = 6s*400
timeData = d*3
numData = ldd
coeffData = 3l*12
denumData = l
libPtrData = lll
constData = 400d
hformat = hdrData + constNData + timeData + numData +  coeffData + 
denumData + libPtrData
header = struct.unpack(hdrData,cls.JPLeph.read(struct.calcsize 
(hdrData)))


constN = struct.unpack(constNData,cls.JPLeph.read 
(struct.calcsize(constNData)))


# Reading in the time data
cls.tstart,cls.tend,cls.tstep = struct.unpack 
(timeData,cls.JPLeph.read(struct.calcsize(timeData)))


# Read in the number of constants and the values for AU and  emrat
nconst, cls.au, cls.emrat = struct.unpack 
(numData,cls.JPLeph.read(struct.calcsize(numData)))


# Reading in the coefficient pointers
cls.coeff = struct.unpack(coeffData,cls.JPLeph.read 
(struct.calcsize(coeffData)))

# Read in the DENUM variable and the libratPtr(3)
(cls.denum, ) = struct.unpack(denumData,cls.JPLeph.read 
(struct.calcsize(denumData)))
cls.libPtr = struct.unpack(libPtrData,cls.JPLeph.read 
(struct.calcsize(libPtrData)))


if cls.denum == 405:
cls.asize = 1018
elif cls.denum == 200:
cls.asize = 826
else:
raise ValueError(JPL ephem file is in unknown format %d  % 
(cls.denum))


Try unpacking in one big chunk using 'hformat' above.  struct should do the 
right thing with structure unpacking if it knows how the entire structure is 
laid out.


C structures use padding to align data elements on natural boundaries 
because it is more efficient for a processor to read DWORDs on DWORD 
(4-byte) boundaries, WORDs on 2-byte boundaries, etc.  The struct module is 
aware of this.  Below a long is 4 bytes and a double is 8 bytes.  If the 
long is first the double would be at offset 4 (not an 8-byte boundary) so 4 
bytes of padding are inserted.  If the double is first the long is at offset 
8 (a 4-byte boundary) and the padding isn't inserted.



struct.calcsize('ld')

16

struct.calcsize('dl')

12

In your case above, the size of the char arrays before the first double is 
not a multiple of 8, so padding is inserted.  Since your example read the 
chunks separately, struct didn't know to insert the padding.


-Mark


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


Re: a simple unicode question

2009-10-21 Thread Scott David Daniels

George Trojan wrote:

Scott David Daniels wrote:

...

And if you are unsure of the name to use:
  import unicodedata
  unicodedata.name(u'\xb0')
'DEGREE SIGN'


 Thanks for all suggestions. It took me a while to find out how to
 configure my keyboard to be able to type the degree sign. I prefer to
 stick with pure ASCII if possible.
 Where are the literals (i.e. u'\N{DEGREE SIGN}') defined? I found
 http://www.unicode.org/Public/5.1.0/ucd/UnicodeData.txt
 Is that the place to look?

I thought the mention of unicodedata would make it clear.

 for n in xrange(sys.maxunicode+1):
try:
nm = unicodedata.name(unichr(n))
except ValueError: pass
else:
if 'tortoise' in nm.lower(): print n, nm


--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to knock a page out of file cache

2009-10-21 Thread Ishwor Gurung
[...]
 I thought of simply opening and writing to the file to dirty it's
 pages, but there no guarantee that pdflush will have already written
 the dirty pages to disk -pretty sure it depends on all the dirty ratio
 and intervals.

 Does anybody know of a system call that will 'knock' the file out of
 file cache?  Can madvise or fadvise do this?

Does this help http://www.westnet.com/~gsmith/content/linux-pdflush.htm ?
(Getting hold of procfs and doing it in Python?)

Also, are you looking for sync(2) http://linux.die.net/man/2/sync?

[...]
-- 
Regards,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to knock a page out of file cache

2009-10-21 Thread Ishwor Gurung
[...]

 Also, are you looking for sync(2) http://linux.die.net/man/2/sync?

Also, maybe mmap.flush([offset, size]) @
http://docs.python.org/library/mmap.html ?
Get the file, mmap it and flush it. The docs has more info on flush(...)

Afaik, ultimately the kernel will control the writebacks of dirty
pages and their frequency of writebacks.
So if you want the shortest path, you can choose to go the /proc path.

[...]
-- 
Regards,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help to convert c++ fonction in python

2009-10-21 Thread Processor-Dev1l
On Oct 18, 8:13 am, Toff christophed...@gmail.com wrote:
 On 18 oct, 02:13, geremy condra debat...@gmail.com wrote:



  On Sat, Oct 17, 2009 at 7:57 PM, David Robinow drobi...@gmail.com wrote:
   On Sat, Oct 17, 2009 at 7:48 PM, geremy condra debat...@gmail.com wrote:
   For the love of baby kittens, please, please, please tell me that
   you do not believe this securely encrypts your data.
    Yeah, I think it's pretty good.
   Can you do better?

  Trivially. Use AES, 3DES, any standard cryptosystem- there are
  literally dozens of excellent, well-studied implementations in
  both C++ and Python, and hardware implementations on many
  processors.

  The cipher listed will fall in a single round of chosen plaintext
  attacks or chosen ciphertext attacks, and with a keylength of
  40 bytes against a message length of 768 will give me roughly
  19 windows on a single encryption. Frequency analysis is
  therefore going to be extremely profitable, not to mention
  trivially easy.

  Geremy Condra

 Thanks a lot Tim !

 @Geremy :
 this is not a methode to encrypt data
 it is more a methode to encode /decode strings

 for exemple to store passwords that need  to be used by others
 programs
 yes it 's insecure
 but there is no secure way to store password that 's need to be
 retrieve

 PS : sorry for my english

Ok, what about SHA1? yeah, it is one-way cipher, but it is also all
you need :).
When user inputs the password, password is hashed using SHA1 and
compared with already stored hash, if hashes are the same, password is
correct. You can use this accross your applications and it will always
work the same.
(if someone forgets his password you can always use random generator
to create new one)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple audio

2009-10-21 Thread Peter Chant
Simon Forman wrote:

 Someone else will probably give you better advice, but have you looked
 at pygame?  IIRC they have a pretty simple audio playback api.

I'm using pygame for something else.  Will it work without the graphics side 
being used? I suppose trying it is the best plan!

Pete

-- 
http://www.petezilla.co.uk

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


Re: Checking a Number for Palindromic Behavior

2009-10-21 Thread Lie Ryan

ru...@yahoo.com wrote:

1) It may look like a homework problem to you but it
 probably isn't.
 Seehttp://groups.google.com/group/comp.lang.python/msg/8ac6db43b09fdc92

Homework comes in many forms - school driven homework should be
treated the same as self driven research, IMO. You're not doing it to
be told the answer, you're likely doing it to learn.


As I said in point (5), you are not in a position to
decide how someone else best learns, even if your guess
that the question is homework, contrary to the evidence
in the url, is correct.


Yes we do. If the person wanted a direct and straight answer (like most 
cheaters) for such a simple question (like integer palindrome), googling 
takes less time and efforts compared to posting to a mailing list.


OTOH, since the poster took the trouble of registering to a newsgroup, 
posting his problem, waiting a few hours for replies, and checking the 
group for replies, requesting clarification, thanking, and getting back 
to normal day activities; this implies that he wanted explanations which 
can only be provided with the more interactive newsgroup instead of a 
relatively static websites.



3) You are not responding only to the original poster;
 there are many other silent readers who are interested
 in the answer and whom you are depriving of knowledge
 by refusing to answer.

MRAB provided a perfect answer - anybody who wants to know more, or
could not connect the dots, can always ask for more information.


No.  Forcing people to beg for bits and pieces of an answer
one at a time, doled out by a cabal of elite gurus, is
humiliating and a disincentive.  If you can answer the question,
do so without all the farting around.  If you don't want too,
or you feel answering in bits and pieces is helpful, fine, do
that, but don't object to someone else providing a direct
answer.


Yes we have the right to complain, because a single post containing a 
direct answer will *destroy the purpose of giving hints*.


Giving direct answer is too tempting for an OP that originally wanted to 
try to solve by their own. It is too easy to copy and even the most 
determined would have a difficult time to resist.


If the OP had wanted a direct answer, he should make an explicit note 
about it. When that happen, the OP is not interested in studying about 
the solution anyway and hints are useless.


Writing a direct answer is much, much, much easier than understanding 
where specifically the OP is having trouble with. We wanted OP to post 
their solution or at least their thought on the problem because we 
wanted to see why the OP is having problems, so we can tailor the reply 
specifically for the OP.


Not giving direct answers promotes active thinking, which is much more 
important for programmers, direct answer gives rote memorization, which 
is useless for programmers due to sophisticated documentations.



4) When you post a specific solution to a question,
 usually a number of other people will respond with
 alternate or better solutions.  While perhaps overkill
 for the original poster who likely will be satisfied
 with any answer, such discussion greatly benefits
 other readers.

See previous.


Most of what I have learned about python from this group
I have learned by reading responses to other people's
questions.  I would not in most cases bother to post a
request for clarification if the answers weren't clear.
So see previous is also my response.


If you're still having problems but won't bother to post a request for 
clarification, that means you don't take your *own problem* seriously 
enough.



Of course, whether you choose to provide a specific
answer to something you think is homework, or not,
is ultimately a personal decision and you are free
to follow your conscious.  Just please don't demand
that every other participant in this group adopt
your personal standards.

When you join a long standing community, you're expected to follow
their conventions. Don't top post, don't do someone else's homework,
etc.


This is the only thing you wrote that resonates with me.
I would never dream of moving to Spain and immediately
start agitating to end the cruel sport of bullfighting
(though if it were already a contentious issue I might
join those already objecting).  I would not move to
France and demand that French people stop drinking wine
because of the problems alcohol causes.  But clp is
somehow different, even assuming that the no homework
help rule is actually a tradition 


it actually is, in most (if not all) newsgroups. Most technical forums 
follows this tradition;


as opposed to a few

dominant personalities and a bunch of wannabe followers.


We ARE all wannabe followers. All humans copy from their elders and, if 
you haven't realized, that is what education is about. Also, tradition 
means handing over, passing on (wikipedia), a dominant personalities 
and a bunch of wannabe followers fits into that description; the 
culture of the dominant 

Re: Struct on on x86_64 mac os x

2009-10-21 Thread Ulrich Eckhardt
Tommy Grav wrote:
 I have created a binary file that saves this struct from some C code:
 
struct recOneData {
   char label[3][84];
   char constName[400][6];
 double timeData[3];
   long int numConst;
 double AU;
 double EMRAT;
   long int coeffPtr[12][3];
   long int DENUM;
   long int libratPtr[3];
   };

The sizes of integers and floating-point numbers vary between different
systems. Further, floating point layout and endianess also vary between
systems. If you want to define a file format, you can't simply write a C
struct to disk.

Suggestions:
1. Use JSON or XML or any other text-based metaformat to build your format
upon.
2. Otherwise, make up your mind byte by byte how the things should look on
disk. That includes things like whether 'DENUM' is 2, 3, 5 or 42 bytes
large and which byte comes first. You can then write code to write the
structure to disk in that format, both in C and in Python. For the C part,
also take a look at stdint.h, which contains useful aliases for integers
with a well-defined size.

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


md5 strange error

2009-10-21 Thread catalinf...@gmail.com
I have this error , what happen ?

Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38)
[GCC 4.3.2 20080917 (Red Hat 4.3.2-4)] on linux2
Type help, copyright, credits or license for more information.
 import md5
 pass = md5.new()
  File stdin, line 1
pass = md5.new()
 ^
SyntaxError: invalid syntax
 m = md5.new()
 n = md5.new()

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


Re: Checking a Number for Palindromic Behavior

2009-10-21 Thread rurpy
On 10/20/2009 11:48 AM, Falcolas wrote:
 On Oct 20, 11:18 am, ru...@yahoo.com wrote:
 Why *not* answering a question in comp.lang.python
 because you think it is homework is BAD.

I got a little over-hyperbolic above and muddied the waters.
More accurately, this should have been, Why insisting
that nobody directly answer a question in comp.lang.python
because you think it is homework is BAD.
I think the content of my previous posts made clear that
if you want to provide an experiential answer to a question,
that is fine.  But please don't assume that is necessarily
the only style of answer or the best.

Since this is the rebuttal to several of your points below
I will refer to it as A1 and reference it below.

 1) It may look like a homework problem to you but it
  probably isn't.
  Seehttp://groups.google.com/group/comp.lang.python/msg/8ac6db43b09fdc92

 Homework comes in many forms - school driven homework should be
 treated the same as self driven research, IMO. You're not doing it to
 be told the answer, you're likely doing it to learn.

As I said in point (5), you are not in a position to
decide how someone else best learns, even if your guess
that the question is homework, contrary to the evidence
in the url, is correct.

 2) When you publicly accuse someone of cheating (and
  even asking is tantamount to an accusation unless done
  very tactfully), especially without anything more than
  your feelings to back it up, you will likely anger
  the poster, contribute to an generally unpleasant
  atmosphere in the newsgroup, and intimidate other
  people who want to ask legitimate questions.

 Arguing with a long standing Usenet and clp traditions are just as
 likely to cause an unpleasant atmosphere.

Matter of which is the least worst I suppose.  As for
tradition, see below.

 3) You are not responding only to the original poster;
  there are many other silent readers who are interested
  in the answer and whom you are depriving of knowledge
  by refusing to answer.

 MRAB provided a perfect answer - anybody who wants to know more, or
 could not connect the dots, can always ask for more information.

No.  Forcing people to beg for bits and pieces of an answer
one at a time, doled out by a cabal of elite gurus, is
humiliating and a disincentive.  If you can answer the question,
do so without all the farting around.  If you don't want too,
or you feel answering in bits and pieces is helpful, fine, do
that, but don't object to someone else providing a direct
answer.

 4) When you post a specific solution to a question,
  usually a number of other people will respond with
  alternate or better solutions.  While perhaps overkill
  for the original poster who likely will be satisfied
  with any answer, such discussion greatly benefits
  other readers.

 See previous.

Most of what I have learned about python from this group
I have learned by reading responses to other people's
questions.  I would not in most cases bother to post a
request for clarification if the answers weren't clear.
So see previous is also my response.

 5) Although working out an answer oneself is the usual
  goal of homework problems, it is not the only way to
  learn.  Often, when one is really stuck, one can learn
  what one is supposed to by seeing the fully worked out
  problem's answer.  You, who don't know anything about
  the poster, are not in a position to decide for him/her
  what the best way of learning is.  The poster is also
  free to ignore your answer if he/she chooses.

 Again, if the original, directing answer was not sufficient, the
 original poster is welcome to ask for more information. Doing so will
 likely help them as much as it would help this silent reader
 population.

See previous.

 6) Please don't apply your abstract moral standards to
  the entire rest of the world, knowing nothing about the
  particular circumstances of the poster.

 So, let the poster give the circumstances. We have just as much right
 to question his motives as you have to question ours.

See A1 at top.

 7) If the poster is determined to cheat, he/she will do
  so with or without your help.  Your self-righteous
  stand will serve only to generate the above undesirable
  results without changing the poster's behavior.

 How did MRAB's response negatively affect anybody?

See A1 at top.

 Of course, whether you choose to provide a specific
 answer to something you think is homework, or not,
 is ultimately a personal decision and you are free
 to follow your conscious.  Just please don't demand
 that every other participant in this group adopt
 your personal standards.

 When you join a long standing community, you're expected to follow
 their conventions. Don't top post, don't do someone else's homework,
 etc.

This is the only thing you wrote that resonates with me.
I would never dream of moving to Spain and immediately
start agitating to end the cruel sport of bullfighting
(though if it were already a contentious issue I might
join 

Re: Checking a Number for Palindromic Behavior

2009-10-21 Thread Falcolas
On Oct 20, 11:18 am, ru...@yahoo.com wrote:
 Why *not* answering a question in comp.lang.python
 because you think it is homework is BAD.

 1) It may look like a homework problem to you but it
  probably isn't.
  Seehttp://groups.google.com/group/comp.lang.python/msg/8ac6db43b09fdc92

Homework comes in many forms - school driven homework should be
treated the same as self driven research, IMO. You're not doing it to
be told the answer, you're likely doing it to learn.

 2) When you publicly accuse someone of cheating (and
  even asking is tantamount to an accusation unless done
  very tactfully), especially without anything more than
  your feelings to back it up, you will likely anger
  the poster, contribute to an generally unpleasant
  atmosphere in the newsgroup, and intimidate other
  people who want to ask legitimate questions.

Arguing with a long standing Usenet and clp traditions are just as
likely to cause an unpleasant atmosphere.

 3) You are not responding only to the original poster;
  there are many other silent readers who are interested
  in the answer and whom you are depriving of knowledge
  by refusing to answer.

MRAB provided a perfect answer - anybody who wants to know more, or
could not connect the dots, can always ask for more information.

 4) When you post a specific solution to a question,
  usually a number of other people will respond with
  alternate or better solutions.  While perhaps overkill
  for the original poster who likely will be satisfied
  with any answer, such discussion greatly benefits
  other readers.

See previous.

 5) Although working out an answer oneself is the usual
  goal of homework problems, it is not the only way to
  learn.  Often, when one is really stuck, one can learn
  what one is supposed to by seeing the fully worked out
  problem's answer.  You, who don't know anything about
  the poster, are not in a position to decide for him/her
  what the best way of learning is.  The poster is also
  free to ignore your answer if he/she chooses.

Again, if the original, directing answer was not sufficient, the
original poster is welcome to ask for more information. Doing so will
likely help them as much as it would help this silent reader
population.

 6) Please don't apply your abstract moral standards to
  the entire rest of the world, knowing nothing about the
  particular circumstances of the poster.

So, let the poster give the circumstances. We have just as much right
to question his motives as you have to question ours.

 7) If the poster is determined to cheat, he/she will do
  so with or without your help.  Your self-righteous
  stand will serve only to generate the above undesirable
  results without changing the poster's behavior.

How did MRAB's response negatively affect anybody?

 Of course, whether you choose to provide a specific
 answer to something you think is homework, or not,
 is ultimately a personal decision and you are free
 to follow your conscious.  Just please don't demand
 that every other participant in this group adopt
 your personal standards.

When you join a long standing community, you're expected to follow
their conventions. Don't top post, don't do someone else's homework,
etc.

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


Re: Struct on on x86_64 mac os x

2009-10-21 Thread Mark Dickinson
On Oct 20, 10:51 pm, Tommy Grav tg...@pha.jhu.edu wrote:
 I have created a binary file that saves this struct from some C code:

    struct recOneData {
           char label[3][84];
           char constName[400][6];
         double timeData[3];
       long int numConst;
         double AU;
         double EMRAT;
       long int coeffPtr[12][3];
       long int DENUM;
       long int libratPtr[3];
       };

 I try to read this file with python (ActiveState 2.6.3 on x86_64 Mac  
 OS X 10.6.1) using the
 code below the hdrData and constNData are fine, while from the  
 timeData onwards there
 are obvious problems. The code below works fine for a 32bit binary  
 read with i386 python
 2.5.2. Does anyone know what the proper format of a C double and long  
 int is for a x86_64
 binary?

As others have said, it depends on the platform.  But on OS X 10.6,
and on most 64-bit Linuxes that I've met, I'm fairly sure that
sizeof(long int) == sizeof(double) == 8.  In contrast, 64-bit
Windows on the same hardware will probably have sizeof(long int) == 4.


      def read_header(cls):
          hdrData = 84s*3
          constNData = 6s*400

I'm confused:  why is this not 400s*6 rather than 6s*400?
Doesn't constName[400][6] mean 6 lots of constName[400]?
Similarly for 84s*3.  This might be making a difference to
the padding.

[...]

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


Text file to XML representation

2009-10-21 Thread kak...@gmail.com
Hello,
I would like to make a program that takes a text file with the
following representation:

outlook = sunny
|   humidity = 70: yes (2.0)
|   humidity  70: no (3.0)
outlook = overcast: yes (4.0)
outlook = rainy
|   windy = TRUE: no (2.0)
|   windy = FALSE: yes (3.0)

and convert it to xml file for example:
?xml version=1.0 encoding=UTF-8?
DecisionTree type=DescisionTree
Test attribute=outlook operator== value=sunny
Test attribute=humidity operator=lt;= value=70
Output decision=yes info=(2.0)/
/Test
Test attribute=humidity operator= value=70
Output decision=no info=(3.0)/
/Test
/Test
Test attribute=outlook operator== value=overcast
Output decision=yes info=(4.0)/
/Test
Test attribute=outlook operator== value=rainy
Test attribute=windy operator== value=TRUE
Output decision=no info=(2.0)/
/Test
Test attribute=windy operator== value=FALSE
Output decision=yes info=(3.0)/
/Test
/Test
/DecisionTree

Is there a way to do it?
Please help
Thanks in advance
Antonis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Frameworks

2009-10-21 Thread Bruno Desthuilliers

Emmanuel Surleau a écrit :

Emmanuel Surleau a écrit :

Django : very strong integration, excellent documentation and support,
huge community, really easy to get started with. And possibly a bit more
mature and stable...

One strong point in favour of Django: it follows Python's philosophy of
batteries included, and features a large array of plugins. There are
also numerous other add-ons created by the community.

Also, it has a pretty great administration interface.

It still manages to retain flexibility, but you're basically stuck with
Django's ORM

You're by no way stuck with Django's ORM - you are perfectly free not
to use it. But then you'll obviously loose quite a lot of useful
features and 3rd part apps...


You lose most of what makes it worth using Django,


Mmmm... I beg to disagree. You still have the core framework (request / 
response handling, sessions etc), the templating system, the form API 
etc. As far as I'm concerned, it's quite enough to make it worth.



(which is OK for simple things) and templating language (which is
OK as long as you don't need custom tags).

Custom tags are nothing complicated.


Compared to custom tags in, say, Mako?


I lack _working_ experience with Mako (only played with it), but I found 
it to sometimes have a bend backbward feel. One nice thing with 
Django's templates is the very straightforward approach. Might not be as 
smart and elegant - and certainly not as powerful, I won't even discuss 
this point -, but hey, it JustWork(tm), and my fellow html coders can 
use it without difficulty.


Don't misunderstand me - as a computer programmer, I of course find Mako 
to be way above Django's template. But this doesn't make the latter bad, 
and from the average html coder POV Django is easier to grasp. But well, 
this has been debatted to hell and back, so let's not waste time with this.


Having to implement a mini-parser for 
each single tag


Most of the mini-parser stuff is so very easily factored out I'm 
afraid I won't buy your argument.

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


Re: md5 strange error

2009-10-21 Thread Super Zyper
On 21 oct, 10:11, catalinf...@gmail.com catalinf...@gmail.com
wrote:
 I have this error , what happen ?

 Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38)
 [GCC 4.3.2 20080917 (Red Hat 4.3.2-4)] on linux2
 Type help, copyright, credits or license for more information. 
 import md5
  pass = md5.new()

   File stdin, line 1
     pass = md5.new()
          ^
 SyntaxError: invalid syntax

  m = md5.new()
  n = md5.new()

 Regards !

pass is a Python reserved keyword so you can't use it as a
variable !

This keywork can be used to conserve python indentation but you have
nothing especially to do.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: md5 strange error

2009-10-21 Thread Xavier Ho
On Wed, Oct 21, 2009 at 6:11 PM, catalinf...@gmail.com 
catalinf...@gmail.com wrote:

  pass = md5.new()
  File stdin, line 1
pass = md5.new()
 ^
 SyntaxError: invalid syntax


pass is a keyword in Python, you can't use it as an identifier.

Try password instead.

Cheers,
Xav
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is Islam?-1

2009-10-21 Thread omer azazi
On 12 أكتوبر, 05:42, TerryP bigboss1...@gmail.com wrote:
 On Oct 11, 11:25 pm, omer azazi omariman...@gmail.com wrote:

 I appologise if I appear _rude_, but this is comp.lang.python -- it is
 for the discussion of Python and related projects that were created by
 men and women. A discussion about faith does not belong in
 comp.lang.python, unless you are writing a program in Python to help
 people study the Qur’an, or some other holy book. .

 Good luck and good bye.

         THANK YOU.





so, if i send programs about islam , will u accept it ?!!

or u just hate the word Islam ???
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Struct on on x86_64 mac os x

2009-10-21 Thread Mark Dickinson
On Oct 21, 9:18 am, Mark Dickinson dicki...@gmail.com wrote:
 On Oct 20, 10:51 pm, Tommy Grav tg...@pha.jhu.edu wrote:

       def read_header(cls):
           hdrData = 84s*3
           constNData = 6s*400

 I'm confused:  why is this not 400s*6 rather than 6s*400?
 Doesn't constName[400][6] mean 6 lots of constName[400]?
 Similarly for 84s*3.  This might be making a difference to
 the padding.

Sorry, that's wrong.  It won't make any difference to the padding,
since arrays don't have padding in C:  sizeof(char[3]) is 3,
and sizeof(char[3][84]) is 3*84=252.

So your problem is likely just the difference between sizeof(long)
from one platform to another.

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


Re: a simple unicode question

2009-10-21 Thread Chris Jones
On Wed, Oct 21, 2009 at 12:20:35AM EDT, Nobody wrote:
 On Tue, 20 Oct 2009 17:56:21 +, George Trojan wrote:

[..]

  Where are the literals (i.e. u'\N{DEGREE SIGN}') defined? 
 
 You can get them from the unicodedata module, e.g.:
 
   import unicodedata
   for i in xrange(0x1):
 n = unicodedata.name(unichr(i),None)
 if n is not None:
   print i, n

Python rocks!

Just curious, why did you choose to set the upper boundary at 0x?

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


Re: md5 strange error

2009-10-21 Thread Tim Golden

catalinf...@gmail.com wrote:

I have this error , what happen ?

Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38)
[GCC 4.3.2 20080917 (Red Hat 4.3.2-4)] on linux2
Type help, copyright, credits or license for more information.

import md5
pass = md5.new()

  File stdin, line 1
pass = md5.new()
 ^
SyntaxError: invalid syntax


pass is a keyword, as in:

def f ():
 pass

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


Re: md5 strange error

2009-10-21 Thread Kushal Kumaran
On Wed, Oct 21, 2009 at 1:41 PM, catalinf...@gmail.com
catalinf...@gmail.com wrote:
 I have this error , what happen ?

 Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38)
 [GCC 4.3.2 20080917 (Red Hat 4.3.2-4)] on linux2
 Type help, copyright, credits or license for more information.
 import md5
 pass = md5.new()
  File stdin, line 1
    pass = md5.new()
         ^
 SyntaxError: invalid syntax
 m = md5.new()
 n = md5.new()


pass is a python keyword.  You'll need a different name for the variable.

-- 
regards,
kushal
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode again ... default codec ...

2009-10-21 Thread Lele Gaifax
Gabriel Genellina gagsl-...@yahoo.com.ar writes:

 DON'T do that. Really. Changing the default encoding is a horrible,
 horrible hack and causes a lot of problems.
 ...
 More reasons:
 http://tarekziade.wordpress.com/2008/01/08/syssetdefaultencoding-is-evil/
 See also this recent thread in python-dev:
 http://comments.gmane.org/gmane.comp.python.devel/106134

This is a problem that appears quite often, against which I have yet to
see a general workaround, or even a safe pattern. I must confess that
most often I just give up and change the if 0: line in
sitecustomize.py to enable a reasonable default...

A week ago I met another incarnation of the problem that I finally
solved by reloading the sys module, a very ugly way, don't tell me, and
I really would like to know a better way of doing it.

The case is simple enough: a unit test started failing miserably, with a
really strange traceback, and a quick pdb session revealed that the
culprit was nosetest, when it prints out the name of the test, using
some variant of print testfunc.__doc__: since the latter happened to
be a unicode string containing some accented letters, that piece of
nosetest's code raised an encoding error, that went untrapped...

I tried to understand the issue, until I found that I was inside a fresh
new virtualenv with python 2.6 and the sitecustomize wasn't even
there. So, even if my shell environ was UTF-8 (the system being a Ubuntu
Jaunty), within that virtualenv Python's stdout encoding was
'ascii'. Rightly so, nosetest failed to encode the accented letters to
that.

I could just rephrase the test __doc__, or remove it, but to avoid
future noise I decided to go with the deprecated reload(sys) trick,
done as early as possible... damn, it's just a test suite after all!

Is there a correct way of dealing with this? What should nosetest
eventually do to initialize it's sys.output.encoding reflecting the
system's settings? And on the user side, how could I otherwise fix it (I
mean, without resorting to the reload())?

Thank you,
ciao, lele.
-- 
nickname: Lele Gaifax| Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas| comincerò ad aver paura di chi mi copia.
l...@nautilus.homeip.net | -- Fortunato Depero, 1929.

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


Re: What is Islam?-1

2009-10-21 Thread Ben Finney
omer azazi omariman...@gmail.com writes:

 On 12 أكتوبر, 05:42, TerryP bigboss1...@gmail.com wrote:
  On Oct 11, 11:25 pm, omer azazi omariman...@gmail.com wrote:
 
  I appologise if I appear _rude_, but this is comp.lang.python -- it
  is for the discussion of Python and related projects that were
  created by men and women. A discussion about faith does not belong
  in comp.lang.python, unless you are writing a program in Python to
  help people study the Qur’an, or some other holy book. .

 so, if i send programs about islam , will u accept it ?!!

To the extent that they are Python programs, and the discussion remains
about the Python programming language, that would be fine.

 or u just hate the word Islam ???

Hatred is as off-topic here as is discussion of religion. Please take it
elsewhere.

-- 
 \   “I love and treasure individuals as I meet them, I loathe and |
  `\ despise the groups they identify with and belong to.” —George |
_o__) Carlin, 2007 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Text file to XML representation

2009-10-21 Thread Bruno Desthuilliers

kak...@gmail.com a écrit :

Hello,
I would like to make a program that takes a text file with the
following representation:

outlook = sunny
|   humidity = 70: yes (2.0)
|   humidity  70: no (3.0)
outlook = overcast: yes (4.0)
outlook = rainy
|   windy = TRUE: no (2.0)
|   windy = FALSE: yes (3.0)

and convert it to xml file for example:


(snip xml)


Is there a way to do it?


More than one. But I'd stronly suggest something like PyParsing + 
ElementTree.


PyParsing : http://pyparsing.wikispaces.com/

ElementTree : is now in the stdlib, so refer to the FineManual


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


Re: a simple unicode question

2009-10-21 Thread Bruno Desthuilliers

beSTEfar a écrit :
(snip)
 When parsing strings, use Regular Expressions.

And now you have _two_ problems g

For some simple parsing problems, Python's string methods are powerful 
enough to make REs overkill. And for any complex enough parsing (any 
recursive construct for example - think XML, HTML, any programming 
language etc), REs are just NOT enough by themselves - you need a full 
blown parser.


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


Re: Struct on on x86_64 mac os x

2009-10-21 Thread Dave Angel

Mark Dickinson wrote:

On Oct 20, 10:51 pm, Tommy Grav tg...@pha.jhu.edu wrote:
  

I have created a binary file that saves this struct from some C code:

   struct recOneData {
  char label[3][84];
  char constName[400][6];
double timeData[3];
  long int numConst;
double AU;
double EMRAT;
  long int coeffPtr[12][3];
  long int DENUM;
  long int libratPtr[3];
  };

I try to read this file with python (ActiveState 2.6.3 on x86_64 Mac  
OS X 10.6.1) using the
code below the hdrData and constNData are fine, while from the  
timeData onwards there
are obvious problems. The code below works fine for a 32bit binary  
read with i386 python
2.5.2. Does anyone know what the proper format of a C double and long  
int is for a x86_64

binary?



As others have said, it depends on the platform.  But on OS X 10.6,
and on most 64-bit Linuxes that I've met, I'm fairly sure that
sizeof(long int) =sizeof(double) == 8.  In contrast, 64-bit
Windows on the same hardware will probably have sizeof(long int) =4.

  

 def read_header(cls):
 hdrData =84s*3
 constNData =6s*400



I'm confused:  why is this not 400s*6 rather than 6s*400?
Doesn't constName[400][6] mean 6 lots of constName[400]?
Similarly for 84s*3.  This might be making a difference to
the padding.

[...]

--
Mark

  
I don't know much about the 64 bit Unix platforms, since 64bits was just 
a dream last time I used Unix.


But I'd guess that your problem is that double will be aligned to 8 
bytes on some platforms.  Since your characters don't add up to a 
multiple of 8, you'd have some paddding between them.



When you get to define your own file format, the old advice was to:
  1) use text form if possible, where the endianness and the alignment 
are non-issues.
  2) If you must use binary data, directly stored, then put the 
largest-aligned items at the beginning of the struct, and work down to 
the smallest alignments.  That way there is never any padding, except at 
the end of the struct.  For that, add a dummy character field of a size 
appropriate to bring the size to a multiple of the largest alignment, 
generally 8.   You'd still have to worry about endianness, but at least 
padding goes away.


Incidentally, though it doesn't affect the padding issues, I believe you 
have the meaning of constName[400][6] backwards.  This refers to 400 
strings of 6 bytes each.  In C, the definitions are in row-major order.


DaveA

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


Re: odd mmap behavior

2009-10-21 Thread Carl Banks
On Oct 20, 5:03 pm, Brett brettgra...@gmail.com wrote:
 I'm trying to read and write from /dev/mem on a linux system using the
 mmap module. When I run this minimal example:
 ---
 import os, mmap

 MAP_MASK = mmap.PAGESIZE - 1

 addr = 0x48088024

 f = os.open(/dev/mem, os.O_RDWR | os.O_SYNC)
 m = mmap.mmap(f, mmap.PAGESIZE, mmap.MAP_SHARED, mmap.PROT_WRITE |
 mmap.PROT_READ, offset=addr  ~MAP_MASK)
 m.seek(addr  MAP_MASK)
 c = m.read_byte()
 print c
 m.close()
 os.close(f)
 ---

 I get the following error:
 Unhandled fault: external abort on non-linefetch (0x1018) at
 0x40020024
 Bus error

 and python crashes. What is odd is that if I try to read the same
 memory address using the devmem2 program (i'll attach the source at
 the end), everything works fine. Here are the truncated straces for
 each program:

 - devmem2 0x48088024 -
 open(/dev/mem, O_RDWR|O_SYNC)         = 3
 fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
 0) = 0x4001f000
 write(1, /dev/mem opened.\n, 17)      = 17
 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0x48088) =
 0x4002
 write(1, Memory mapped at address 0x40020..., 37) = 37
 write(1, Value at address 0x48088024 (0x4..., 46) = 46
 munmap(0x4002, 4096)                = 0
 close(3)                                = 0
 io_submit(0, 0, 0xfbad2088 unfinished ... exit status 0
 Process 1635 detached

 -- the above minimal python example -
 open(/dev/mem, O_RDWR|O_SYNC|O_LARGEFILE) = 3
 fstat64(3, {st_mode=S_IFCHR|0640, st_rdev=makedev(1, 1), ...}) = 0
 dup(3)                                  = 4
 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0x48088) =
 0x4002
 --- SIGBUS (Bus error) @ 0 (0) ---
 +++ killed by SIGBUS +++
 Process 1633 detached

 Am I using mmap incorrectly?

Looks like you're using it ok to me.

One thing to keep in mind is that the offset parameter was added to
mmap recently, only in Python 2.6 I think, so it might not have been
so battle-tested as the rest of Python.  Also, I would guess the file-
like methods (seek, read, etc.) are not commonly used.  Perhaps those
methods don't play nice with the offset method?  It's possible the
mmap object doesn't recon the seek pointer relative to the offset,
meaning you'd have to use m.seek(addr) instead of m.seek(addr 
MAP_MASK)

Another possibility is that the mmap object is accessing the memory
with bad alignment (when I see bus error the first thing I think of is
that a word was read from a non-word-aligned address).  You don't
happen to be running this on a Power PC?  What happens when you try
accessing the mmap data like an regular array?

All speculation, but my gut feeling is bug in mmap module.


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


Re: PySide PyQt

2009-10-21 Thread Carl Banks
On Oct 20, 6:45 pm, rm rmcorresp...@gmail.com wrote:
 On Oct 20, 6:14 pm, Robert Kern robert.k...@gmail.com wrote:

  On 2009-10-20 16:48 PM, rm wrote:

   Have you guys heard about PySide:

  http://www.pyside.org/

   It is basically the same as PyQt (Qt bindings for Python), but
   licensed with the LGPL instead of GPL.  The FAQ explains a bit more
   history.  Looks like the end for PyQt if you ask me.

  Welcome to two months ago. :-)

  PySide still needs a fair chunk of work to go before it could really be 
  claimed
  that it is a wholesale replacement for PyQt, but it looks like it will be a
  compelling alternative.

 I did a search for PySide here and only saw the announcement.  I was
 surprised that no discussion ensued, did I miss it.  So, I assumed
 that not a lot of people knew about it and wanted to help spread the
 word and hear some opinions.  But, what you say is probably right on
 the mark.  Thanks.

One thing PySide has going against it is the shared library binaries
are a lot larger than PyQT4's, because of its use of boost::python.
Not a good thing for something that exists so that it can be put on a
mobile device.

Still, I see PySide being the eventual end of my GUI toolkit journeys.


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


Re: SimpleXMLRPCServer clobbering sys.stderr? (2.5.2)

2009-10-21 Thread Brian Quinlan

Do you have some code that we could see that provokes the problem?

Cheers,
Brian

Joseph Turian wrote:

I was having a mysterious problem with SimpleXMLRPCServer. (I am using
Python 2.5.2)
The request handlers were sometimes failing without any error message
to the log output.

What I discovered was perplexing.
I had some 'print' statements in the handers that, assuming the
request would be handled, would print just fine. When I switched to
'print  sys.stderr', the request handlers would just fail
completely, and not make the sys.stderr output that I desired.

It seems that SimpleXMLRPCServer is clobbering stderr in some bizarre
and silent-error-causing way.
I can't really find any documentation of explanation of this
phenomenon.

Could someone please illuminate it for me?

Best,
   Joseph


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


Re: odd mmap behavior

2009-10-21 Thread Brett
On Oct 21, 8:02 am, Carl Banks pavlovevide...@gmail.com wrote:
 On Oct 20, 5:03 pm, Brett brettgra...@gmail.com wrote:



  I'm trying to read and write from /dev/mem on a linux system using the
  mmap module. When I run this minimal example:
  ---
  import os, mmap

  MAP_MASK = mmap.PAGESIZE - 1

  addr = 0x48088024

  f = os.open(/dev/mem, os.O_RDWR | os.O_SYNC)
  m = mmap.mmap(f, mmap.PAGESIZE, mmap.MAP_SHARED, mmap.PROT_WRITE |
  mmap.PROT_READ, offset=addr  ~MAP_MASK)
  m.seek(addr  MAP_MASK)
  c = m.read_byte()
  print c
  m.close()
  os.close(f)
  ---

  I get the following error:
  Unhandled fault: external abort on non-linefetch (0x1018) at
  0x40020024
  Bus error

  and python crashes. What is odd is that if I try to read the same
  memory address using the devmem2 program (i'll attach the source at
  the end), everything works fine. Here are the truncated straces for
  each program:

  - devmem2 0x48088024 -
  open(/dev/mem, O_RDWR|O_SYNC)         = 3
  fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
  mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
  0) = 0x4001f000
  write(1, /dev/mem opened.\n, 17)      = 17
  mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0x48088) =
  0x4002
  write(1, Memory mapped at address 0x40020..., 37) = 37
  write(1, Value at address 0x48088024 (0x4..., 46) = 46
  munmap(0x4002, 4096)                = 0
  close(3)                                = 0
  io_submit(0, 0, 0xfbad2088 unfinished ... exit status 0
  Process 1635 detached

  -- the above minimal python example -
  open(/dev/mem, O_RDWR|O_SYNC|O_LARGEFILE) = 3
  fstat64(3, {st_mode=S_IFCHR|0640, st_rdev=makedev(1, 1), ...}) = 0
  dup(3)                                  = 4
  mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0x48088) =
  0x4002
  --- SIGBUS (Bus error) @ 0 (0) ---
  +++ killed by SIGBUS +++
  Process 1633 detached

  Am I using mmap incorrectly?

 Looks like you're using it ok to me.

 One thing to keep in mind is that the offset parameter was added to
 mmap recently, only in Python 2.6 I think, so it might not have been
 so battle-tested as the rest of Python.  Also, I would guess the file-
 like methods (seek, read, etc.) are not commonly used.  Perhaps those
 methods don't play nice with the offset method?  It's possible the
 mmap object doesn't recon the seek pointer relative to the offset,
 meaning you'd have to use m.seek(addr) instead of m.seek(addr 
 MAP_MASK)

 Another possibility is that the mmap object is accessing the memory
 with bad alignment (when I see bus error the first thing I think of is
 that a word was read from a non-word-aligned address).  You don't
 happen to be running this on a Power PC?  What happens when you try
 accessing the mmap data like an regular array?

 All speculation, but my gut feeling is bug in mmap module.

 Carl Banks

I also posted this question to the linux-omap list and received some
helpful (and timely) assistance. I'm running this on an ARM (omap
3530, gumstix). Here is the take-home message (from the omap technical
reference and reported to me here 
http://www.spinics.net/lists/linux-omap/msg19347.html):
CAUTION
The GP timer registers are limited to 32-bit and 16-bit data accesses;
8-bit access is not allowed and can corrupt the register content.

So... instead of calling mmap.read_byte() i'm calling mmap.read(4).
The thing I'm still wondering, is if python 'under-the-hood' is still
making 8-bit accesses. I thought it was fixed, but just got another
'Unhandled fault'. Any hints?

Also, thanks for the suggestion about accessing it as an array. I will
try to find out if one method of access (array-like or reading as a
string) results in more errors.
-- 
http://mail.python.org/mailman/listinfo/python-list


Optimal Character recognition using python

2009-10-21 Thread pytart
Hello ,
   I have a project to develop a basic character recognition
module in python using backpropagation and artificial neural networks.
I would be very helpful if u cud give me some helpful links for the
project. I am having problems with the implementation part of the
project, the backpropagation concept is OK with me.

thnx in advance
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Optimal Character recognition using python

2009-10-21 Thread Diez B. Roggisch
pytart wrote:

 Hello ,
I have a project to develop a basic character recognition
 module in python using backpropagation and artificial neural networks.
 I would be very helpful if u cud give me some helpful links for the
 project. I am having problems with the implementation part of the
 project, the backpropagation concept is OK with me.

Homework? How about you show us the code you have, and what actual problems
you have, and then we might be able to help.

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


Re: odd mmap behavior

2009-10-21 Thread Carl Banks
On Oct 21, 6:50 am, Brett brettgra...@gmail.com wrote:
 I also posted this question to the linux-omap list and received some
 helpful (and timely) assistance. I'm running this on an ARM (omap
 3530, gumstix). Here is the take-home message (from the omap technical
 reference and reported to me 
 herehttp://www.spinics.net/lists/linux-omap/msg19347.html):
 CAUTION
 The GP timer registers are limited to 32-bit and 16-bit data accesses;
 8-bit access is not allowed and can corrupt the register content.

 So... instead of calling mmap.read_byte() i'm calling mmap.read(4).
 The thing I'm still wondering, is if python 'under-the-hood' is still
 making 8-bit accesses. I thought it was fixed, but just got another
 'Unhandled fault'. Any hints?

Yes, read() operates by copying the value as a string, which means
byte-by-byte access.  (It's probably using a function such as
PyString_FromStringAndLen under the convers.)

I'm not sure you can even access the the memory through the mmap
object except byte-by-byte.

One way to get word access would be to use buffer protocol, which mmap
supports, and create a numpy ndarray that references the mmap data.


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


Re: Simple audio

2009-10-21 Thread AK Eric
Yep, you can run it without any kind of GUI to my knowledge.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PySide PyQt

2009-10-21 Thread Robert Kern

On 2009-10-21 07:11 AM, Carl Banks wrote:


One thing PySide has going against it is the shared library binaries
are a lot larger than PyQT4's, because of its use of boost::python.
Not a good thing for something that exists so that it can be put on a
mobile device.


I believe the consensus amongst the PySide devs is to move to the Shiboken 
wrapper generator which uses the raw CPython API. It still needs a lot of work, 
though.


--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


error when using Pmw.BLT

2009-10-21 Thread Yang
I tried to follow the following code demonstrating the use of Pwm.BLT:

 from Tkinter import *
 import Pmw
 master = Tk()
 g = Pmw.Blt.Graph( master )

I got the following error message after I typed the last line:

Traceback (most recent call last):
  File stdin, line 1, in module
  File C:\Python26\lib\site-packages\Pmw\Pmw_1_3\lib\PmwBlt.py, line
260, in _
_init__
Tkinter.Widget.__init__(self, master, _graphCommand, cnf, kw)
  File C:\Python26\lib\lib-tk\Tkinter.py, line 1932, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: invalid command name ::blt::graph


I am a newbie in python. Does anybody know what causes this error? I
am running python 2.6.3 under windows xp.

Thanks for your help!!


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


error when using Pmw.BLT

2009-10-21 Thread Yang Yang
Hello,

I tried to follow the following code demonstrating the use of Pmw.BLT:

 from Tkinter import *
 import Pmw
 master = Tk()
 g = Pmw.Blt.Graph( master )

I got the following error message after I typed the last line:

Traceback (most recent call last):
 File stdin, line 1, in module
 File C:\Python26\lib\site-packages\Pmw\Pmw_1_3\lib\PmwBlt.py, line
260, in _
_init__
   Tkinter.Widget.__init__(self, master, _graphCommand, cnf, kw)
 File C:\Python26\lib\lib-tk\Tkinter.py, line 1932, in __init__
   (widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: invalid command name ::blt::graph


I am a newbie in python. Does anybody know what causes this error? I
am running python 2.6.3 under windows xp.

Thanks for your help!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help to convert c++ fonction in python

2009-10-21 Thread geremy condra
On Wed, Oct 21, 2009 at 3:28 AM, Processor-Dev1l
processor.de...@gmail.com wrote:
 On Oct 18, 8:13 am, Toff christophed...@gmail.com wrote:
 On 18 oct, 02:13, geremy condra debat...@gmail.com wrote:



  On Sat, Oct 17, 2009 at 7:57 PM, David Robinow drobi...@gmail.com wrote:
   On Sat, Oct 17, 2009 at 7:48 PM, geremy condra debat...@gmail.com 
   wrote:
   For the love of baby kittens, please, please, please tell me that
   you do not believe this securely encrypts your data.
    Yeah, I think it's pretty good.
   Can you do better?

  Trivially. Use AES, 3DES, any standard cryptosystem- there are
  literally dozens of excellent, well-studied implementations in
  both C++ and Python, and hardware implementations on many
  processors.

  The cipher listed will fall in a single round of chosen plaintext
  attacks or chosen ciphertext attacks, and with a keylength of
  40 bytes against a message length of 768 will give me roughly
  19 windows on a single encryption. Frequency analysis is
  therefore going to be extremely profitable, not to mention
  trivially easy.

  Geremy Condra

 Thanks a lot Tim !

 @Geremy :
 this is not a methode to encrypt data
 it is more a methode to encode /decode strings

 for exemple to store passwords that need  to be used by others
 programs
 yes it 's insecure
 but there is no secure way to store password that 's need to be
 retrieve

 PS : sorry for my english

 Ok, what about SHA1? yeah, it is one-way cipher, but it is also all
 you need :).
 When user inputs the password, password is hashed using SHA1 and
 compared with already stored hash, if hashes are the same, password is
 correct. You can use this accross your applications and it will always
 work the same.
 (if someone forgets his password you can always use random generator
 to create new one)

Unfortunately, without input from the dev team over there
I can't do much more than bemoan the current situation.
You are right though- while replay attacks would be a
problem it would be much more resistant to attack than
the current system.

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


Re: error when using Pmw.BLT

2009-10-21 Thread Robert Kern

On 2009-10-21 10:50 AM, Yang Yang wrote:

Hello,

I tried to follow the following code demonstrating the use of Pmw.BLT:

  from Tkinter import *
  import Pmw
  master = Tk()
  g = Pmw.Blt.Graph( master )

I got the following error message after I typed the last line:

Traceback (most recent call last):
  File stdin, line 1, in module
  File C:\Python26\lib\site-
packages\Pmw\Pmw_1_3\lib\PmwBlt.py, line
260, in _
_init__
Tkinter.Widget.__init__(self, master, _graphCommand, cnf, kw)
  File C:\Python26\lib\lib-tk\Tkinter.py, line 1932, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: invalid command name ::blt::graph


I am a newbie in python. Does anybody know what causes this error? I
am running python 2.6.3 under windows xp.


You need to install BLT for Tcl. It is not a standard part of Tcl, and it is not 
included in the version of Tcl that comes bundled with Python.


--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Python Developer role in San Francisco

2009-10-21 Thread Jaime Bott
Hello:

Would it be okay to post a San Francisco-based contract Python Developer
role on this group list? Here is the link to the URL:
http://docs.google.com/View?id=dtc9xms_77hsrm8pc3.

Unfortunately since the company is in stealth, I can't give out to much info
via email. You can find a bit more info about one of the founders here:
www.benkeighran.com.

Feel free to forward the job spec out to your network. Any help would be
greatly appreciated.

Thanks!

Jaime
ja...@chompapps.com
www.jaimebott.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a simple unicode question

2009-10-21 Thread Nobody
On Wed, 21 Oct 2009 05:16:56 -0400, Chris Jones wrote:

  Where are the literals (i.e. u'\N{DEGREE SIGN}') defined? 
 
 You can get them from the unicodedata module, e.g.:
 
  import unicodedata
  for i in xrange(0x1):
n = unicodedata.name(unichr(i),None)
if n is not None:
  print i, n
 
 Python rocks!
 
 Just curious, why did you choose to set the upper boundary at 0x?

Characters outside the 16-bit range aren't supported on all builds. They
won't be supported on most Windows builds, as Windows uses 16-bit Unicode
extensively:

Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit 
(Intel)] on
win32
 unichr(0x1)
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: unichr() arg not in range(0x1) (narrow Python build)

Note that narrow builds do understand names outside of the BMP, and
generate surrogate pairs for them:

 u'\N{LINEAR B SYLLABLE B008 A}'
u'\U0001'
 len(_)
2

Whether or not using surrogates in this context is a good idea is open to
debate. What's the advantage of a multi-wchar string over a multi-byte
string?

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


Re: Checking a Number for Palindromic Behavior

2009-10-21 Thread rurpy
On 10/21/2009 01:40 AM, Lie Ryan wrote:
 ru...@yahoo.com wrote:
 1) It may look like a homework problem to you but it
  probably isn't.
  Seehttp://groups.google.com/group/comp.lang.python/msg/8ac6db43b09fdc92
 Homework comes in many forms - school driven homework should be
 treated the same as self driven research, IMO. You're not doing it to
 be told the answer, you're likely doing it to learn.

 As I said in point (5), you are not in a position to
 decide how someone else best learns, even if your guess
 that the question is homework, contrary to the evidence
 in the url, is correct.

 Yes we do. If the person wanted a direct and straight answer (like most
 cheaters) for such a simple question (like integer palindrome), googling
 takes less time and efforts compared to posting to a mailing list.

In that particular case, yes.  However many problem are
much more difficult to search for.  You're also assuming
that every poster is a perfect decision-maker when deciding
how to seek help.  Sorry, people are not as perfect as you
think.

 OTOH, since the poster took the trouble of registering to a newsgroup,
 posting his problem, waiting a few hours for replies, and checking the
 group for replies, requesting clarification, thanking, and getting back
 to normal day activities;

You are way overstating the effort involved here.
Especially if the poster has posted to the group before
usually the only significant effort is writing the message
(and thinking about the responses of course but that has
to be done no matter where the poster seeks help.)

You are also way understating the effort in Googling
something.  I have spent literally days wading through
thousands of pages of Google results trying to find
accuate info before.

 this implies that he wanted explanations which
 can only be provided with the more interactive newsgroup instead of a
 relatively static websites.

No it doesn't imply any such thing.  It is exactly this
narrowness of focus, this inability to see alternate
explanations, that is leading you to think that
providing hints is the single one and only right
way of responding to any simple question on this list.

They may post here because, ...(ready for this?)...
they want a direct answer to their question!

 3) You are not responding only to the original poster;
  there are many other silent readers who are interested
  in the answer and whom you are depriving of knowledge
  by refusing to answer.
 MRAB provided a perfect answer - anybody who wants to know more, or
 could not connect the dots, can always ask for more information.

 No.  Forcing people to beg for bits and pieces of an answer
 one at a time, doled out by a cabal of elite gurus, is
 humiliating and a disincentive.  If you can answer the question,
 do so without all the farting around.  If you don't want too,
 or you feel answering in bits and pieces is helpful, fine, do
 that, but don't object to someone else providing a direct
 answer.

 Yes we have the right to complain,

Of course.  This is usenet (or a very open mailing list
depending on your perspective.)  You can complain or
say anything you want.  As can I.  However people will
pay attention to you or not based on the degree of sense
you make (in an ideal world) or based on other group-
dynamic things (in an imperfect world) or a combination
of both (in the real world).

 because a single post containing a
 direct answer will *destroy the purpose of giving hints*.

Which is precisely the problem,  You claim that purpose
is the single, only, best way of helping the person you are
answering.  I am simply claiming you don't know that, can't
in a general sense know that.  If you want to play teacher
and provide that style of answer, fine.  But since you
(collective) have demonstrated that you are not even
able to accurately identify when someone is asking about
a homework problem (but are still arrogantly willing to
try), it is pretty reasonable for us thems to doubt your
claims that you know the best way to answer questions
here.  Since you haven't demonstrated your style of
answers is best, it unreasonable for you to insist
that it be the only style allowed.

Please remember, I am only saying that simply answering
a question, as asked, is not a bad thing.  I really
would have thought this would be pretty uncontentious.
But then again, this is clp.

 Giving direct answer is too tempting for an OP that originally wanted to
 try to solve by their own. It is too easy to copy and even the most
 determined would have a difficult time to resist.

Baloney.  When I ask a question in any forum I read
all the answers (although I might only skim those that
are duplicative, off-topic, or otherwise less relevent
to my goals).  I extract from them all the information
I can.  And if two answers provide the same information,
what's your problem?  Are you angry that someone else
provided a more effective answer than you thus devaluing
your effort?  Sorry, but that's just life.  If it's
any 

Re: ANN: Testoob 1.15 released

2009-10-21 Thread Jorgen Grahn
On Mon, 2009-10-19, oripel wrote:
 On Oct 14, 5:59 pm, Jorgen Grahn grahn+n...@snipabacken.se wrote:
 But this sentence on the home page

     The documentation is sadly outdated, but may be
     a starting point:

 made me stop looking.  As far as I can tell, you cannot even find out
 what's so advanced about it (or why advanced is a good thing)
 without starting to use it.  A brief comparison with module unittest
 (which I am rather unhappy with) would have been nice, too.

 Those are good points Jorgen, thanks.

 The briefest summary I would give is:
 (a) You can run your unittest suites unmodified (so it's easy to try
 out)
 (b) The test running options have the potential to whet your appetite:

 % testoob -h
 Usage
 =
   testoob [options] [test1 [test2 [...]]]

 examples:
   testoob  - run default set of tests
   testoob MyTestSuite  - run suite 'MyTestSuite'
   testoob MyTestCase.testSomething - run MyTestCase.testSomething
   testoob MyTestCase   - run all 'test*' test methods in
 MyTestCase

 Options
 ===
[dozens of options snipped]

Oh, good. Both (a) and (b) are certainly good info for the web page.

Many of the options are for transforming the output -- something I
prefer (as a Unix guy) to do myself with a filtering script I have
control over. Others will like it though, and I like some of the other
options -- especially the one which lists all tests, and the run
tests which match this string option.

/Jorgen

-- 
  // Jorgen Grahn grahn@  Oo  o.   .  .
\X/ snipabacken.se   O  o   .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: error when using Pmw.BLT

2009-10-21 Thread Yang
On Oct 21, 12:13 pm, Robert Kern robert.k...@gmail.com wrote:
 On 2009-10-21 10:50 AM, Yang Yang wrote:



  Hello,

  I tried to follow the following code demonstrating the use of Pmw.BLT:

    from Tkinter import *
    import Pmw
    master = Tk()
    g = Pmw.Blt.Graph( master )

  I got the following error message after I typed the last line:

  Traceback (most recent call last):
    File stdin, line 1, in module
    File C:\Python26\lib\site-
  packages\Pmw\Pmw_1_3\lib\PmwBlt.py, line
  260, in _
  _init__
      Tkinter.Widget.__init__(self, master, _graphCommand, cnf, kw)
    File C:\Python26\lib\lib-tk\Tkinter.py, line 1932, in __init__
      (widgetName, self._w) + extra + self._options(cnf))
  _tkinter.TclError: invalid command name ::blt::graph

  I am a newbie in python. Does anybody know what causes this error? I
  am running python 2.6.3 under windows xp.

 You need to install BLT for Tcl. It is not a standard part of Tcl, and it is 
 not
 included in the version of Tcl that comes bundled with Python.

 --
 Robert Kern

 I have come to believe that the whole world is an enigma, a harmless enigma
   that is made terrible by our own mad attempt to interpret it as though it 
 had
   an underlying truth.
    -- Umberto Eco

Thanks, Robert!

Here is another question on this. I am running Python 2.6.3 which uses
Tcl 8.5. I could not find the BLT binary source for Tcl 8.5. The
latest version is for Tcl 8.4. How could I install BLT? For example,
can I change the default Tcl version that Python has access to to some
older version?

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


Re: error when using Pmw.BLT

2009-10-21 Thread Robert Kern

On 2009-10-21 12:38 PM, Yang wrote:


Here is another question on this. I am running Python 2.6.3 which uses
Tcl 8.5. I could not find the BLT binary source for Tcl 8.5. The
latest version is for Tcl 8.4. How could I install BLT? For example,
can I change the default Tcl version that Python has access to to some
older version?


I'm afraid I don't really know.

--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: Cpython optimization

2009-10-21 Thread Francesco Bochicchio
Il Wed, 21 Oct 2009 10:28:55 -0700, Qrees ha scritto:

 Hello
 
 As my Master's dissertation I chose Cpython optimization. That's why i'd
 like to ask what are your suggestions what can be optimized. Well, I
 know that quite a lot. I've downloaded the source code (I plan to work
 on Cpython 2.6 and I've downloaded 2.6.3 release). By looking at the
 code I've found comment's like this can be optimized by... etc. but
 maybe you guide me what should I concentrate on in my work?
 
 I've 6-7 month  for this and If I create something decent I can publish
 it.
 
 Thank you in advance for any help

If you don't know yet, you could find interesting this project:

   http://code.google.com/p/unladen-swallow/

They too are trying to improve CPython speed.

If you are thinking of language variations  that trade some flexiblity 
for speed, you might be interested in Cython:

http://www.cython.org/

As a simple and plain python user, I would value a version of cython that 
can be used to built faster executables out of almost-python code (that 
is python code with a few additional restructions). Maybe using typing 
inference to avoid declaring explicitely the variable types.

Another interesting place to go is pypy : http://codespeak.net/pypy/dist/
pypy/doc/ . They too have developed a restriced version of python 
(RPython, I think) which should be faster than CPython. They don't work 
with CPython code base, but could give you ideas on what are the 
bottlenecks of python as a language.

Ciao
-
FB


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


Windows file paths, again

2009-10-21 Thread Dan Guido
I'm trying to write a few methods that normalize Windows file paths.
I've gotten it to work in 99% of the cases, but it seems like my code
still chokes on '\x'. I've pasted my code below, can someone help me
figure out a better way to write this? This seems overly complicated
for such a simple problem...


# returns normalized filepath with arguments removed
def remove_arguments(filepath):
#print removing args from:  + filepath
(head, tail) = os.path.split(filepath)
pathext = os.environ['PATHEXT'].split(;)

while(tail != ''):
#print trying:  + os.path.join(head,tail)

# does it just work?
if os.path.isfile(os.path.join(head, tail)):
#print it just worked
return os.path.join(head, tail)

# try every extension
for ext in pathext:
if os.path.isfile(os.path.join(head, tail) + ext):
return os.path.join(head, tail) + ext

# remove the last word, try again
tail = tail.split()[:-1]
tail =  .join(tail)

return None

escape_dict={'\a':r'\a',
   '\b':r'\b',
   '\c':r'\c',
   '\f':r'\f',
   '\n':r'\n',
   '\r':r'\r',
   '\t':r'\t',
   '\v':r'\v',
   '\'':r'\'',
   #'\':r'\',
   '\0':r'\0',
   '\1':r'\1',
   '\2':r'\2',
   '\3':r'\3',
   '\4':r'\4',
   '\5':r'\5',
   '\6':r'\6',
   '\7':r'\a', #i have no idea
   '\8':r'\8',
   '\9':r'\9'}

def raw(text):
Returns a raw string representation of text
new_string=''
for char in text:
try:
new_string+=escape_dict[char]
#print escaped
except KeyError:
new_string+=char
#print keyerror
#print new_string
return new_string

# returns the normalized path to a file if it exists
# returns None if it doesn't exist
def normalize_path(path):
#print not normal:  + path

# make sure it's not blank
if(path == ):
return None

# get rid of mistakenly escaped bytes
path = raw(path)
#print step1:  + path

# remove quotes
path = path.replace('', '')
#print step2:  + path

#convert to lowercase
lower = path.lower()
#print step3:  + lower

# expand all the normally formed environ variables
expanded = os.path.expandvars(lower)
#print step4:  + expanded

# chop off \??\
if expanded[:4] == \\??\\:
expanded = expanded[4:]
#print step5:  + expanded

# strip a leading '/'
if expanded[:1] == \\:
expanded = expanded[1:]
#print step7:  + expanded

systemroot = os.environ['SYSTEMROOT']

# sometimes systemroot won't have %
r = re.compile('systemroot', re.IGNORECASE)
expanded = r.sub(systemroot, expanded)
#print step8:  + expanded

# prepend the %systemroot% if its missing
if expanded[:8] == system32 or syswow64:
expanded = os.path.join(systemroot, expanded)
#print step9:  + expanded

stripped = remove_arguments(expanded.lower())

# just in case you're running as LUA
# this is a race condition but you can suck it
if(stripped):
if os.access(stripped, os.R_OK):
return stripped

return None

def test_normalize():
test1 = \??\C:\WINDOWS\system32\Drivers\CVPNDRVA.sys
test2 = C:\WINDOWS\system32\msdtc.exe
test3 = %SystemRoot%\system32\svchost.exe -k netsvcs
test4 = \SystemRoot\System32\drivers\vga.sys
test5 = system32\DRIVERS\compbatt.sys
test6 = C:\Program Files\ABC\DEC Windows Services\Client Services.exe
test7 = c:\Program Files\Common Files\Symantec Shared\SNDSrvc.exe
test8 = C:\WINDOWS\system32\svchost -k dcomlaunch
test9 = 
test10 = SysWow64\drivers\AsIO.sys
test11 = \SystemRoot\system32\DRIVERS\amdsbs.sys
test12 = C:\windows\system32\xeuwhatever.sys #this breaks everything

print normalize_path(test1)
print normalize_path(test2)
print normalize_path(test3)
print normalize_path(test4)
print normalize_path(test5)
print normalize_path(test6)
print normalize_path(test7)
print normalize_path(test8)
print normalize_path(test9)
print normalize_path(test10)
print normalize_path(test11)
print 

Re: a simple unicode question

2009-10-21 Thread rurpy
On Oct 21, 4:59 am, Bruno Desthuilliers bruno.
42.desthuilli...@websiteburo.invalid wrote:
 beSTEfar a écrit :
 (snip)
   When parsing strings, use Regular Expressions.

 And now you have _two_ problems g

 For some simple parsing problems, Python's string methods are powerful
 enough to make REs overkill. And for any complex enough parsing (any
 recursive construct for example - think XML, HTML, any programming
 language etc), REs are just NOT enough by themselves - you need a full
 blown parser.

But keep in mind that many XML, HTML, etc parsing problems
are restricted to a subset where you know the nesting depth
is limited (often to 0 or 1), and for that large set of
problems, RE's *are* enough.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best vi / emacs python features

2009-10-21 Thread Hans Georg Schaathun
On Wed, 07 Oct 2009 18:44:03 +0200, Jean-Michel Pichavant
  jeanmic...@sequans.com wrote:
:  When opposing vi to emacs, there's is no possibility you get 
:  constructive and objective answer, because basically, what can do with 
:  one, you can also do it with the other.

You seem rather negative.  I could not see any request from OP to 
oppose vi to emacs.  All I could see was a questions about features 
people actually use.

And as another user of less than 1% of the features in vim, I found
the few posts actually focusing on that question rather interesting.
Thanks.

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


Re: Windows file paths, again

2009-10-21 Thread Diez B. Roggisch
Dan Guido wrote:

 I'm trying to write a few methods that normalize Windows file paths.
 I've gotten it to work in 99% of the cases, but it seems like my code
 still chokes on '\x'. I've pasted my code below, can someone help me
 figure out a better way to write this? This seems overly complicated
 for such a simple problem...
 
 
 # returns normalized filepath with arguments removed
 def remove_arguments(filepath):
 #print removing args from:  + filepath
 (head, tail) = os.path.split(filepath)
 pathext = os.environ['PATHEXT'].split(;)
 
 while(tail != ''):
 #print trying:  + os.path.join(head,tail)
 
 # does it just work?
 if os.path.isfile(os.path.join(head, tail)):
 #print it just worked
 return os.path.join(head, tail)
 
 # try every extension
 for ext in pathext:
 if os.path.isfile(os.path.join(head, tail) + ext):
 return os.path.join(head, tail) + ext
 
 # remove the last word, try again
 tail = tail.split()[:-1]
 tail =  .join(tail)
 
 return None
 
 escape_dict={'\a':r'\a',
'\b':r'\b',
'\c':r'\c',
'\f':r'\f',
'\n':r'\n',
'\r':r'\r',
'\t':r'\t',
'\v':r'\v',
'\'':r'\'',
#'\':r'\',
'\0':r'\0',
'\1':r'\1',
'\2':r'\2',
'\3':r'\3',
'\4':r'\4',
'\5':r'\5',
'\6':r'\6',
'\7':r'\a', #i have no idea
'\8':r'\8',
'\9':r'\9'}
 
 def raw(text):
 Returns a raw string representation of text
 new_string=''
 for char in text:
 try:
 new_string+=escape_dict[char]
 #print escaped
 except KeyError:
 new_string+=char
 #print keyerror
 #print new_string
 return new_string
 
 # returns the normalized path to a file if it exists
 # returns None if it doesn't exist
 def normalize_path(path):
 #print not normal:  + path
 
 # make sure it's not blank
 if(path == ):
 return None
 
 # get rid of mistakenly escaped bytes
 path = raw(path)
 #print step1:  + path
 
 # remove quotes
 path = path.replace('', '')
 #print step2:  + path
 
 #convert to lowercase
 lower = path.lower()
 #print step3:  + lower
 
 # expand all the normally formed environ variables
 expanded = os.path.expandvars(lower)
 #print step4:  + expanded
 
 # chop off \??\
 if expanded[:4] == \\??\\:
 expanded = expanded[4:]
 #print step5:  + expanded
 
 # strip a leading '/'
 if expanded[:1] == \\:
 expanded = expanded[1:]
 #print step7:  + expanded
 
 systemroot = os.environ['SYSTEMROOT']
 
 # sometimes systemroot won't have %
 r = re.compile('systemroot', re.IGNORECASE)
 expanded = r.sub(systemroot, expanded)
 #print step8:  + expanded
 
 # prepend the %systemroot% if its missing
 if expanded[:8] == system32 or syswow64:
 expanded = os.path.join(systemroot, expanded)
 #print step9:  + expanded
 
 stripped = remove_arguments(expanded.lower())
 
 # just in case you're running as LUA
 # this is a race condition but you can suck it
 if(stripped):
 if os.access(stripped, os.R_OK):
 return stripped
 
 return None
 
 def test_normalize():
 test1 = \??\C:\WINDOWS\system32\Drivers\CVPNDRVA.sys
 test2 = C:\WINDOWS\system32\msdtc.exe
 test3 = %SystemRoot%\system32\svchost.exe -k netsvcs
 test4 = \SystemRoot\System32\drivers\vga.sys
 test5 = system32\DRIVERS\compbatt.sys
 test6 = C:\Program Files\ABC\DEC Windows Services\Client Services.exe
 test7 = c:\Program Files\Common Files\Symantec Shared\SNDSrvc.exe
 test8 = C:\WINDOWS\system32\svchost -k dcomlaunch
 test9 = 
 test10 = SysWow64\drivers\AsIO.sys
 test11 = \SystemRoot\system32\DRIVERS\amdsbs.sys
 test12 = C:\windows\system32\xeuwhatever.sys #this breaks everything

If I'm getting this right, what you try to do is to convert characters that
come from string-literal escape-codes to their literal representation. Why?

A simple

  test12 = rC:\windows\system32\xeuwhatever.sys

is all you need - note the leading r. Then 

  test12[2] == \\ # need escape on the right because of backslashes at end
of raw-string-literals rule.

holds.

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


Re: convert pyc (python 2.4) to py

2009-10-21 Thread Peng Yu
On Tue, Oct 20, 2009 at 4:42 PM, Diez B. Roggisch de...@nospam.web.de wrote:
 Peng Yu schrieb:

 I have a .pyc file generated by python 2.4. My current python is of
 version 2.6. I'm wondering how to generate the corresponding .py file
 from it.

 http://www.crazy-compilers.com/decompyle/

Is there any free one?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: convert pyc (python 2.4) to py

2009-10-21 Thread Chris Rebert
On Wed, Oct 21, 2009 at 11:35 AM, Peng Yu pengyu...@gmail.com wrote:
 On Tue, Oct 20, 2009 at 4:42 PM, Diez B. Roggisch de...@nospam.web.de wrote:
 Peng Yu schrieb:

 I have a .pyc file generated by python 2.4. My current python is of
 version 2.6. I'm wondering how to generate the corresponding .py file
 from it.

 http://www.crazy-compilers.com/decompyle/

 Is there any free one?

There's an older version of the software at:
http://sourceforge.net/projects/decompyle/
but it's not maintained like the service (just see the last-modified
date on it) and you'll have to figure out how to use it by yourself.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


equivalent to globals(), locals() for nonlocal variables?

2009-10-21 Thread geremy condra
I decided to play around with nonlocal declarations today, and was
somewhat surprised when a call to nonlocals() resulted in 'nonlocals
is not defined'. Is there an a standard equivalent to globals() or
locals() for variables in outer nested scopes?

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


Re: Windows file paths, again

2009-10-21 Thread Dan Guido
Hi Diez,

The source of the string literals is ConfigParser, so I can't just
mark them with an 'r'.

config = ConfigParser.RawConfigParser()
config.read(filename)
crazyfilepath = config.get(name, ImagePath)
normalfilepath = normalize_path(crazyfilepath)

The ultimate origin of the strings is the _winreg function. Here I
also can't mark them with an 'r'.

regkey = OpenKey(HKEY_LOCAL_MACHINE,
SYSTEM\\CurrentControlSet\\Services\\ + name)
crazyimagepath = QueryValueEx(regkey, ImagePath)[0]
CloseKey(key)

--
Dan Guido



On Wed, Oct 21, 2009 at 2:34 PM, Diez B. Roggisch de...@nospam.web.de wrote:
 Dan Guido wrote:

 I'm trying to write a few methods that normalize Windows file paths.
 I've gotten it to work in 99% of the cases, but it seems like my code
 still chokes on '\x'. I've pasted my code below, can someone help me
 figure out a better way to write this? This seems overly complicated
 for such a simple problem...


 # returns normalized filepath with arguments removed
 def remove_arguments(filepath):
 #print removing args from:  + filepath
 (head, tail) = os.path.split(filepath)
 pathext = os.environ['PATHEXT'].split(;)

 while(tail != ''):
 #print trying:  + os.path.join(head,tail)

 # does it just work?
 if os.path.isfile(os.path.join(head, tail)):
 #print it just worked
 return os.path.join(head, tail)

 # try every extension
 for ext in pathext:
 if os.path.isfile(os.path.join(head, tail) + ext):
 return os.path.join(head, tail) + ext

 # remove the last word, try again
 tail = tail.split()[:-1]
 tail =  .join(tail)

 return None

 escape_dict={'\a':r'\a',
            '\b':r'\b',
            '\c':r'\c',
            '\f':r'\f',
            '\n':r'\n',
            '\r':r'\r',
            '\t':r'\t',
            '\v':r'\v',
            '\'':r'\'',
            #'\':r'\',
            '\0':r'\0',
            '\1':r'\1',
            '\2':r'\2',
            '\3':r'\3',
            '\4':r'\4',
            '\5':r'\5',
            '\6':r'\6',
            '\7':r'\a', #i have no idea
            '\8':r'\8',
            '\9':r'\9'}

 def raw(text):
 Returns a raw string representation of text
 new_string=''
 for char in text:
 try:
 new_string+=escape_dict[char]
 #print escaped
 except KeyError:
 new_string+=char
 #print keyerror
 #print new_string
 return new_string

 # returns the normalized path to a file if it exists
 # returns None if it doesn't exist
 def normalize_path(path):
 #print not normal:  + path

 # make sure it's not blank
 if(path == ):
 return None

 # get rid of mistakenly escaped bytes
 path = raw(path)
 #print step1:  + path

 # remove quotes
 path = path.replace('', '')
 #print step2:  + path

 #convert to lowercase
 lower = path.lower()
 #print step3:  + lower

 # expand all the normally formed environ variables
 expanded = os.path.expandvars(lower)
 #print step4:  + expanded

 # chop off \??\
 if expanded[:4] == \\??\\:
 expanded = expanded[4:]
 #print step5:  + expanded

 # strip a leading '/'
 if expanded[:1] == \\:
 expanded = expanded[1:]
 #print step7:  + expanded

 systemroot = os.environ['SYSTEMROOT']

 # sometimes systemroot won't have %
 r = re.compile('systemroot', re.IGNORECASE)
 expanded = r.sub(systemroot, expanded)
 #print step8:  + expanded

 # prepend the %systemroot% if its missing
 if expanded[:8] == system32 or syswow64:
 expanded = os.path.join(systemroot, expanded)
 #print step9:  + expanded

 stripped = remove_arguments(expanded.lower())

 # just in case you're running as LUA
 # this is a race condition but you can suck it
 if(stripped):
 if os.access(stripped, os.R_OK):
 return stripped

 return None

 def test_normalize():
 test1 = \??\C:\WINDOWS\system32\Drivers\CVPNDRVA.sys
 test2 = C:\WINDOWS\system32\msdtc.exe
 test3 = %SystemRoot%\system32\svchost.exe -k netsvcs
 test4 = \SystemRoot\System32\drivers\vga.sys
 test5 = system32\DRIVERS\compbatt.sys
 test6 = C:\Program Files\ABC\DEC Windows Services\Client Services.exe
 test7 = c:\Program Files\Common Files\Symantec Shared\SNDSrvc.exe
 test8 = C:\WINDOWS\system32\svchost -k dcomlaunch
 test9 = 
 test10 = SysWow64\drivers\AsIO.sys
 test11 = \SystemRoot\system32\DRIVERS\amdsbs.sys
 test12 = C:\windows\system32\xeuwhatever.sys #this breaks everything

 If I'm getting this right, what you try to do is to convert characters that
 come from string-literal escape-codes to their literal representation. Why?

 A simple

  test12 = rC:\windows\system32\xeuwhatever.sys

 is all you need - note the leading r. Then

  test12[2] == \\ # need escape on the right because of backslashes at end
 of raw-string-literals rule.

 holds.

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

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


Re: a splitting headache

2009-10-21 Thread David C Ullrich
On Tue, 20 Oct 2009 15:22:55 -0700, Mensanator wrote:

 On Oct 20, 1:51 pm, David C Ullrich dullr...@sprynet.com wrote:
 On Thu, 15 Oct 2009 18:18:09 -0700, Mensanator wrote:
  All I wanted to do is split a binary number into two lists, a list of
  blocks of consecutive ones and another list of blocks of consecutive
  zeroes.

  But no, you can't do that.

  c = '001110'
  c.split('0')
  ['', '', '1', '', '', '', '11', '']

  Ok, the consecutive delimiters appear as empty strings for reasons
  unknown (except for the first one). Except when they start or end the
  string in which case the first one is included.

  Maybe there's a reason for this inconsistent behaviour but you won't
  find it in the documentation.

 Wanna bet? I'm not sure whether you're claiming that the behavior is
 not specified in the docs or the reason for it. The behavior certainly
 is specified. I conjecture you think the behavior itself is not
 specified,
 
 The problem is that the docs give a single example
 
 '1,,2'.split(',')
 ['1','','2']
 
 ignoring the special case of leading/trailing delimiters. Yes, if you
 think it through, ',1,,2,'.split(',') should return ['','1','','2','']
 for exactly the reasons you give.
 
 Trouble is, we often find ourselves doing ' 1  2  '.split() which
 returns
 ['1','2'].
 
 I'm not saying either behaviour is wrong, it's just not obvious that the
 one behaviour doesn't follow from the other and the documentation could
 be
 a little clearer on this matter. It might make a bit more sense to
 actually
 mention the slpit(sep) behavior that split() doesn't do.

Have you _read_ the docs? They're quite clear on the difference
between no sep (or sep=None) and sep=something:

If sep is given, consecutive delimiters are not grouped together and are 
deemed to delimit empty strings (for example, '1,,2'.split(',') returns 
['1', '', '2']). The sep argument may consist of multiple characters (for 
example, '123'.split('') returns ['1', '2', '3']). Splitting an 
empty string with a specified separator returns [''].

If sep is not specified or is None, a different splitting algorithm is 
applied: runs of consecutive whitespace are regarded as a single 
separator, and the result will contain no empty strings at the start or 
end if the string has leading or trailing whitespace. Consequently, 
splitting an empty string or a string consisting of just whitespace with 
a None separator returns []. 

 
 because your description of what's happening,

 consecutive delimiters appear as empty strings for reasons

  unknown (except for the first one). Except when they start or end the
  string in which case the first one is included

 is at best an awkward way to look at it. The delimiters are not
 appearing as empty strings.

 You're asking to split  '001110' on '0'. So you're asking for
 strings a, b, c, etc such that

 (*) '001110' = a + '0' + b + '0' + c + '0' + etc

 The sequence of strings you're getting as output satisfies (*) exactly;
 the first '' is what appears before the first delimiter, the second ''
 is what's between the first and second delimiters, etc.

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


Re: Windows file paths, again

2009-10-21 Thread Anthony Tolle
On Oct 21, 3:20 pm, Dan Guido dgu...@gmail.com wrote:
 Hi Diez,

 The source of the string literals is ConfigParser, so I can't just
 mark them with an 'r'.

 config = ConfigParser.RawConfigParser()
 config.read(filename)
 crazyfilepath = config.get(name, ImagePath)
 normalfilepath = normalize_path(crazyfilepath)

 The ultimate origin of the strings is the _winreg function. Here I
 also can't mark them with an 'r'.

 regkey = OpenKey(HKEY_LOCAL_MACHINE,
 SYSTEM\\CurrentControlSet\\Services\\ + name)
 crazyimagepath = QueryValueEx(regkey, ImagePath)[0]
 CloseKey(key)

 --
 Dan Guido


I just did a quick test using Python 2.5.1 with the following script
on Windows:

# start of test.py
import ConfigParser
config = ConfigParser.RawConfigParser()
config.read(cfg.ini)
x = config.get(foo, bar)
print x
print repr(x)
from _winreg import *
regkey = OpenKey(HKEY_LOCAL_MACHINE,
rSYSTEM\CurrentControlSet\Services\IPSec)
x = QueryValueEx(regkey, ImagePath)[0]
CloseKey(regkey)
print x
print repr(x)
# end of test.py


Here is the contesnts of cfg.ini:

[foo]
bar=c:\dir\file.txt


Here is the output of the script:

c:\dir\file.txt
'c:\\dir\\file.txt'
system32\DRIVERS\ipsec.sys
u'system32\\DRIVERS\\ipsec.sys'


In either case, I don't see the functions returning strings that
requires special handling.  The backslashes are properly escaped in
the repr of both strings.

Something else must be going on if the strings are getting messed up
along the way.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows file paths, again

2009-10-21 Thread Ethan Furman

Dan Guido wrote:

I'm trying to write a few methods that normalize Windows file paths.
I've gotten it to work in 99% of the cases, but it seems like my code
still chokes on '\x'. I've pasted my code below, can someone help me
figure out a better way to write this? This seems overly complicated
for such a simple problem...



[snip]


test12 = C:\windows\system32\xeuwhatever.sys #this breaks everything


[snip]


--
Dan Guido


That is overly complicated.  I would recommend you use either raw 
strings for windows paths, or double backslashes.


The problem you are observing is that \x (unlike the simpler ones such 
as \t) takes a hex number after the \x, so the whole thing would be, for 
example, \xa9.  Because Python is looking for two hex digits after the 
back-slash, and not finding them, you get the error (long before your 
'fix-it' routine gets a chance to run).


Hope this helps.

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


Re: Frameworks

2009-10-21 Thread Emmanuel Surleau
 Emmanuel Surleau a écrit :
  Emmanuel Surleau a écrit :
  Django : very strong integration, excellent documentation and support,
  huge community, really easy to get started with. And possibly a bit
  more mature and stable...
 
  One strong point in favour of Django: it follows Python's philosophy of
  batteries included, and features a large array of plugins. There are
  also numerous other add-ons created by the community.
 
  Also, it has a pretty great administration interface.
 
  It still manages to retain flexibility, but you're basically stuck with
  Django's ORM
 
  You're by no way stuck with Django's ORM - you are perfectly free not
  to use it. But then you'll obviously loose quite a lot of useful
  features and 3rd part apps...
 
  You lose most of what makes it worth using Django,
 
 Mmmm... I beg to disagree. You still have the core framework (request /
 response handling, sessions etc), the templating system, the form API
 etc. As far as I'm concerned, it's quite enough to make it worth.

The form API is pretty good, but I don't think the rest makes it stand out 
that much, compared to other frameworks. To me, the notion of reusable apps 
and the application ecosystem it allows is Django's most compelling feature. 
You are, of course, welcome to disagree.

  Having to implement a mini-parser for
  each single tag
 
 Most of the mini-parser stuff is so very easily factored out I'm
 afraid I won't buy your argument.

You'll at least agree that in terms of line of codes necessary to implement a 
custom tag, it's very far from optimal, I hope?

Cheers,

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


Re: Windows file paths, again

2009-10-21 Thread Dan Guido
Hi Anthony,

Thanks for your reply, but I don't think your tests have any control
characters in them. Try again with a \v, a \n, or a \x in your input
and I think you'll find it doesn't work as expected.

--
Dan Guido



On Wed, Oct 21, 2009 at 3:50 PM, Anthony Tolle anthony.to...@gmail.com wrote:
 On Oct 21, 3:20 pm, Dan Guido dgu...@gmail.com wrote:
 Hi Diez,

 The source of the string literals is ConfigParser, so I can't just
 mark them with an 'r'.

 config = ConfigParser.RawConfigParser()
 config.read(filename)
 crazyfilepath = config.get(name, ImagePath)
 normalfilepath = normalize_path(crazyfilepath)

 The ultimate origin of the strings is the _winreg function. Here I
 also can't mark them with an 'r'.

 regkey = OpenKey(HKEY_LOCAL_MACHINE,
 SYSTEM\\CurrentControlSet\\Services\\ + name)
 crazyimagepath = QueryValueEx(regkey, ImagePath)[0]
 CloseKey(key)

 --
 Dan Guido


 I just did a quick test using Python 2.5.1 with the following script
 on Windows:

 # start of test.py
 import ConfigParser
 config = ConfigParser.RawConfigParser()
 config.read(cfg.ini)
 x = config.get(foo, bar)
 print x
 print repr(x)
 from _winreg import *
 regkey = OpenKey(HKEY_LOCAL_MACHINE,
 rSYSTEM\CurrentControlSet\Services\IPSec)
 x = QueryValueEx(regkey, ImagePath)[0]
 CloseKey(regkey)
 print x
 print repr(x)
 # end of test.py


 Here is the contesnts of cfg.ini:

 [foo]
 bar=c:\dir\file.txt


 Here is the output of the script:

 c:\dir\file.txt
 'c:\\dir\\file.txt'
 system32\DRIVERS\ipsec.sys
 u'system32\\DRIVERS\\ipsec.sys'


 In either case, I don't see the functions returning strings that
 requires special handling.  The backslashes are properly escaped in
 the repr of both strings.

 Something else must be going on if the strings are getting messed up
 along the way.
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: Object Relational Mappers are evil (a meditation)

2009-10-21 Thread Aaron Watters
On Oct 16, 10:35 am, mario ruggier mario.rugg...@gmail.com wrote:
 On Oct 5, 4:25 pm, Aaron Watters aaron.watt...@gmail.com wrote:

  Occasionally I fantasize about making a non-trivial change
  to one of these programs, but I strongly resist going further
  than that because the ORM meatgrinder makes it somewhere
  between extremely unpleasant and impossible to make any
  non-trivial changes to a non-trivial program, especially after
  it has been populated with data.

 Object-relational mappers are like putting lipstick on a 
 pig:http://gizmoweblog.blogspot.com/2006/10/putting-lipstick-on-pig.html

 m ;-)

Cute, but wrong.  Using ORMs is better than using Object databases.

In my case I use Python to un data created by java/hibernate.
If I was using a java based object database I would be simply stuck.
At least if you use an ORM you have a way to access the information
without writing a program in the programming language that the
ORM was defined in.  Anyway, thanks for all the great comments on
this thread from all you Sarcopterygii and Haplorrhini out there.

  -- Aaron Watters
 http://aaron.oirt.rutgers.edu/myapp/GenBankTree/index

===

SQL is the worst possible data interface language
except for all the others.  -- Churchill (paraphrased)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows file paths, again

2009-10-21 Thread Dave Angel

Dan Guido wrote:

Hi Diez,

The source of the string literals is ConfigParser, so I can't just
mark them with an 'r'.

config =onfigParser.RawConfigParser()
config.read(filename)
crazyfilepath =onfig.get(name, ImagePath)
normalfilepath =ormalize_path(crazyfilepath)

The ultimate origin of the strings is the _winreg function. Here I
also can't mark them with an 'r'.

regkey =penKey(HKEY_LOCAL_MACHINE,
SYSTEM\\CurrentControlSet\\Services\\ + name)
crazyimagepath =ueryValueEx(regkey, ImagePath)[0]
CloseKey(key)

--
Dan Guido



On Wed, Oct 21, 2009 at 2:34 PM, Diez B. Roggisch de...@nospam.web.de wrote:
  

Dan Guido wrote:



I'm trying to write a few methods that normalize Windows file paths.
I've gotten it to work in 99% of the cases, but it seems like my code
still chokes on '\x'. I've pasted my code below, can someone help me
figure out a better way to write this? This seems overly complicated
for such a simple problem...


# returns normalized filepath with arguments removed
def remove_arguments(filepath):
#print removing args from:  + filepath
(head, tail) =s.path.split(filepath)
pathext =s.environ['PATHEXT'].split(;)

while(tail !='):
#print trying:  + os.path.join(head,tail)

# does it just work?
if os.path.isfile(os.path.join(head, tail)):
#print it just worked
return os.path.join(head, tail)

# try every extension
for ext in pathext:
if os.path.isfile(os.path.join(head, tail) + ext):
return os.path.join(head, tail) + ext

# remove the last word, try again
tail =ail.split()[:-1]
tail = .join(tail)

return None

escape_dict=\a':r'\a',
   '\b':r'\b',
   '\c':r'\c',
   '\f':r'\f',
   '\n':r'\n',
   '\r':r'\r',
   '\t':r'\t',
   '\v':r'\v',
   '\'':r'\'',
   #'\':r'\',
   '\0':r'\0',
   '\1':r'\1',
   '\2':r'\2',
   '\3':r'\3',
   '\4':r'\4',
   '\5':r'\5',
   '\6':r'\6',
   '\7':r'\a', #i have no idea
   '\8':r'\8',
   '\9':r'\9'}

def raw(text):
Returns a raw string representation of text
new_string=
for char in text:
try:
new_string+=cape_dict[char]
#print escaped
except KeyError:
new_string+=ar
#print keyerror
#print new_string
return new_string

# returns the normalized path to a file if it exists
# returns None if it doesn't exist
def normalize_path(path):
#print not normal:  + path

# make sure it's not blank
if(path =):
return None

# get rid of mistakenly escaped bytes
path =aw(path)
#print step1:  + path

# remove quotes
path =ath.replace('', '')
#print step2:  + path

#convert to lowercase
lower =ath.lower()
#print step3:  + lower

# expand all the normally formed environ variables
expanded =s.path.expandvars(lower)
#print step4:  + expanded

# chop off \??\
if expanded[:4] =\\??\\:
expanded =xpanded[4:]
#print step5:  + expanded

# strip a leading '/'
if expanded[:1] =\\:
expanded =xpanded[1:]
#print step7:  + expanded

systemroot =s.environ['SYSTEMROOT']

# sometimes systemroot won't have %
r =e.compile('systemroot', re.IGNORECASE)
expanded =.sub(systemroot, expanded)
#print step8:  + expanded

# prepend the %systemroot% if its missing
if expanded[:8] =system32 or syswow64:
expanded =s.path.join(systemroot, expanded)
#print step9:  + expanded

stripped =emove_arguments(expanded.lower())

# just in case you're running as LUA
# this is a race condition but you can suck it
if(stripped):
if os.access(stripped, os.R_OK):
return stripped

return None

def test_normalize():
test1 =\??\C:\WINDOWS\system32\Drivers\CVPNDRVA.sys
test2 =C:\WINDOWS\system32\msdtc.exe
test3 =%SystemRoot%\system32\svchost.exe -k netsvcs
test4 =\SystemRoot\System32\drivers\vga.sys
test5 =system32\DRIVERS\compbatt.sys
test6 =C:\Program Files\ABC\DEC Windows Services\Client Services.exe
test7 =c:\Program Files\Common Files\Symantec Shared\SNDSrvc.exe
test8 =C:\WINDOWS\system32\svchost -k dcomlaunch
test9 =
test10 =SysWow64\drivers\AsIO.sys
test11 =\SystemRoot\system32\DRIVERS\amdsbs.sys
test12 =C:\windows\system32\xeuwhatever.sys #this breaks everything
  

If I'm getting this right, what you try to do is to convert characters that
come from string-literal escape-codes to their literal representation. Why?

A simple

 test12 =C:\windows\system32\xeuwhatever.sys

is all you need - note the leading r. Then

 test12[2] =\\ # need escape on the right because of backslashes at end
of raw-string-literals rule.

holds.

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




  
Your first problem is that you're mixing tabs and spaces in your source 
code.  Dangerous and confusing, not to mention an error in Python 3.x


The second problem is that your test_normalize() is called with a bunch 
of invalid literals.  Backslashes in quote literals need to be escaped, 
or you need to use the raw form of literal.  Now this may have nothing 
to do with the data you get from  ConfigParser or QueryValueEx(), but it 
sure makes testing confusing.


The third problem is 

Re: Windows file paths, again

2009-10-21 Thread Lie Ryan

Dan Guido wrote:

Hi Anthony,

Thanks for your reply, but I don't think your tests have any control
characters in them. Try again with a \v, a \n, or a \x in your input
and I think you'll find it doesn't work as expected.


A path read from a file, config file, or winreg would never contain 
control characters unless they contains that a control character.


My crystal ball thinks that you used eval or exec somewhere in your 
script, which may cause a perfectly escaped path to get unescaped, like 
here:


# python 3
path = 'C:\\path\\to\\somewhere.txt'
script = 'open(%s)' % path# this calls str(path)
exec(script)

OR

you stored the path incorrectly. Try seeing what exactly is stored in 
the registry using regedit.




Remember that escape characters doesn't really exist in the in-memory 
representation of the string. The escape characters exist only in string 
literals (i.e. source code) and when you print the string using repr().

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


Re: Checking a Number for Palindromic Behavior

2009-10-21 Thread Tim Chase

ru...@yahoo.com wrote:

On 10/21/2009 01:40 AM, Lie Ryan wrote:

ru...@yahoo.com wrote:

1) It may look like a homework problem to you but it
 probably isn't.
 Seehttp://groups.google.com/group/comp.lang.python/msg/8ac6db43b09fdc92

Homework comes in many forms - school driven homework should be
treated the same as self driven research, IMO. You're not doing it to
be told the answer, you're likely doing it to learn.

As I said in point (5), you are not in a position to
decide how someone else best learns, even if your guess
that the question is homework, contrary to the evidence
in the url, is correct.


Amusingly, this came along today:
http://lifehacker.com/5386722/get-it-wrong-before-you-google-to-learn-it-better

I'd postulate that the same holds for heaving a question out on 
c.l.p without taking at crack at it yourself.  Try it, and if you 
fail, take your findings to the great Google or to Usenet.  But 
not even trying (or evidencing your effort) is bound to get you 
ignored or derided.  Effectively Hey programmer people, do my 
work for me.



OTOH, since the poster took the trouble of registering to a newsgroup,
posting his problem, waiting a few hours for replies, and checking the
group for replies, requesting clarification, thanking, and getting back
to normal day activities;


You are way overstating the effort involved here.
Especially if the poster has posted to the group before
usually the only significant effort is writing the message
(and thinking about the responses of course but that has
to be done no matter where the poster seeks help.)


While some usenet relays throw up more roadblocks than others, 
with both Google Groups and various other usenet hosts, posting 
to a newsgroup is a pretty simple task with little more effort 
than typing in a couple text-boxes.



You are also way understating the effort in Googling
something.  I have spent literally days wading through
thousands of pages of Google results trying to find
accuate info before.


This seems more to be a lack of your own google-fu...


No it doesn't imply any such thing.  It is exactly this
narrowness of focus, this inability to see alternate
explanations, that is leading you to think that
providing hints is the single one and only right
way of responding to any simple question on this list.

They may post here because, ...(ready for this?)...
they want a direct answer to their question!


The best way to get a direct answer is to show that you've 
already made some effort.  Usually this involves including some 
code.  It's a newsgroup composed of people volunteering their 
time conversing with others, not a vending-machine thanklessly 
spewing free answers.



Which is precisely the problem,  You claim that purpose
is the single, only, best way of helping the person you are
answering.  I am simply claiming you don't know that, can't
in a general sense know that.  If you want to play teacher
and provide that style of answer, fine.  But since you
(collective) have demonstrated that you are not even
able to accurately identify when someone is asking about
a homework problem (but are still arrogantly willing to
try), it is pretty reasonable for us thems to doubt your
claims that you know the best way to answer questions


Just because you can find a few examples where intuition was 
wrong doesn't mean it's not the correct approach.  Contrariwise, 
it's good evidence that many folks laugh it off and give enough 
context to demonstrate it's not homework (such as .  However 
folks clearly do post homework questions to the list (I'm 
particularly amused by the ones that forget to remove the 
question number from the homework they copypasted from) and most 
list-members can detect the scent of homework compared to real work.



Please remember, I am only saying that simply answering
a question, as asked, is not a bad thing.


My hope then is that these people whom you coddle with spoon-fed 
answers end up working with/for you instead of me.


-tkc



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


Re: Windows file paths, again

2009-10-21 Thread Dan Guido
I'm writing a test case right now, will update in a few minutes :-).
I'm using Python 2.6.x

I need to read these values in from a configparser file or the windows
registry and get MD5 sums of the actual files on the filesystem and
copy the files to a new location. The open() method completely barfs
if I don't normalize the paths to the files first. I'll show the list,
just give me a little bit more time to separate the code from my
project that demonstrates this bug.
--
Dan Guido



On Wed, Oct 21, 2009 at 4:49 PM, Lie Ryan lie.1...@gmail.com wrote:
 Dan Guido wrote:

 Hi Anthony,

 Thanks for your reply, but I don't think your tests have any control
 characters in them. Try again with a \v, a \n, or a \x in your input
 and I think you'll find it doesn't work as expected.

 A path read from a file, config file, or winreg would never contain control
 characters unless they contains that a control character.

 My crystal ball thinks that you used eval or exec somewhere in your script,
 which may cause a perfectly escaped path to get unescaped, like here:

 # python 3
 path = 'C:\\path\\to\\somewhere.txt'
 script = 'open(%s)' % path    # this calls str(path)
 exec(script)

 OR

 you stored the path incorrectly. Try seeing what exactly is stored in the
 registry using regedit.



 Remember that escape characters doesn't really exist in the in-memory
 representation of the string. The escape characters exist only in string
 literals (i.e. source code) and when you print the string using repr().
 --
 http://mail.python.org/mailman/listinfo/python-list

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


PyQt4 - remember widget positions

2009-10-21 Thread nusch
Is there any simple command which allows me to save position of all
windows:  QMainWindow, QDialogs and qdockwidgets with their sizes,
dock state and positions ? Or do I need to store those values
manually, how can I do it fast?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking a Number for Palindromic Behavior

2009-10-21 Thread Lie Ryan

ru...@yahoo.com wrote:

On 10/21/2009 01:40 AM, Lie Ryan wrote:

ru...@yahoo.com wrote:

1) It may look like a homework problem to you but it
 probably isn't.
 Seehttp://groups.google.com/group/comp.lang.python/msg/8ac6db43b09fdc92

Homework comes in many forms - school driven homework should be
treated the same as self driven research, IMO. You're not doing it to
be told the answer, you're likely doing it to learn.

As I said in point (5), you are not in a position to
decide how someone else best learns, even if your guess
that the question is homework, contrary to the evidence
in the url, is correct.

Yes we do. If the person wanted a direct and straight answer (like most
cheaters) for such a simple question (like integer palindrome), googling
takes less time and efforts compared to posting to a mailing list.


In that particular case, yes.  However many problem are
much more difficult to search for.  You're also assuming
that every poster is a perfect decision-maker when deciding
how to seek help.  Sorry, people are not as perfect as you
think.


Read again: for such a simple question


this implies that he wanted explanations which
can only be provided with the more interactive newsgroup instead of a
relatively static websites.


No it doesn't imply any such thing.  It is exactly this
narrowness of focus, this inability to see alternate
explanations, that is leading you to think that
providing hints is the single one and only right
way of responding to any simple question on this list.

They may post here because, ...(ready for this?)...
they want a direct answer to their question!


Whooaa, I didn't know that...

Baaakaaa...

They should just say if they want to.


3) You are not responding only to the original poster;
 there are many other silent readers who are interested
 in the answer and whom you are depriving of knowledge
 by refusing to answer.

MRAB provided a perfect answer - anybody who wants to know more, or
could not connect the dots, can always ask for more information.

No.  Forcing people to beg for bits and pieces of an answer
one at a time, doled out by a cabal of elite gurus, is
humiliating and a disincentive.  If you can answer the question,
do so without all the farting around.  If you don't want too,
or you feel answering in bits and pieces is helpful, fine, do
that, but don't object to someone else providing a direct
answer.

Yes we have the right to complain,


Of course.  This is usenet (or a very open mailing list
depending on your perspective.)  You can complain or
say anything you want.  As can I.  However people will
pay attention to you or not based on the degree of sense
you make (in an ideal world) or based on other group-
dynamic things (in an imperfect world) or a combination
of both (in the real world).


I have nothing to say about that, just let others decide.


Giving direct answer is too tempting for an OP that originally wanted to
try to solve by their own. It is too easy to copy and even the most
determined would have a difficult time to resist.


Baloney.  When I ask a question in any forum I read
all the answers (although I might only skim those that
are duplicative, off-topic, or otherwise less relevent
to my goals).  I extract from them all the information
I can.  And if two answers provide the same information,
what's your problem?  Are you angry that someone else
provided a more effective answer than you thus devaluing
your effort?  Sorry, but that's just life.  If it's
any consolation though, I for one note and appreciate
all responses, even if they are duplicative or even wrong.


Effective for one day does not mean it is also effective for the next 
forty-two years.


Education is a long term goal, not just a short-sighted, short-term goal 
like to get the highest mark in the exam or finishing an assignment with 
the best mark in the class.



When that happen, the OP is not interested in studying about
the solution anyway and hints are useless.


Again, a completely unjustified conclusion.


Can you justify your own conclusion then? If you haven't realized, the 
burden of proof is on you who opposes the current long-standing ethics.



As a metaphor, which one do you think is better in the long term:
charities or microcredits?


Both of course.  Why on earth would anyone think there
is a simple, single, best answer for complex problems?


Nope, read again. On the *long term* (as I have stated in the question), 
microcredits is proven to be much more effective to solving poverty. In 
the short term, charities will have much quicker effect but not one that 
is lasting and in fact too much charities makes a lot more problems.


Education have time as much as your life-time, short term quickie answer 
is discouraged in favor of a longer lasting solution. OTOH, if the OP 
wanted to use the script in the workplace; that is a short term goal 
that can often be justified.


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


Re: Cpython optimization

2009-10-21 Thread Qrees
 If you don't know yet, you could find interesting this project:

    http://code.google.com/p/unladen-swallow/

I know about this project. I'll have a look at it, but I'd like to
create something of my own.

 They too are trying to improve CPython speed.

 If you are thinking of language variations  that trade some flexiblity
 for speed, you might be interested in Cython:

 http://www.cython.org/

I was thinking about sacrificing some flexibility of Python and thank
you for pointing me to this project. I didn't about it.

 As a simple and plain python user, I would value a version of cython that
 can be used to built faster executables out of almost-python code (that
 is python code with a few additional restructions). Maybe using typing
 inference to avoid declaring explicitely the variable types.

 Another interesting place to go is pypy :http://codespeak.net/pypy/dist/
 pypy/doc/ . They too have developed a restriced version of python
 (RPython, I think) which should be faster than CPython. They don't work
 with CPython code base, but could give you ideas on what are the
 bottlenecks of python as a language.

 Ciao
 -
 FB

I'd like to hear a word from developers, what they think about
this :).

BTW: My seminar deals with object oriented programming.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows file paths, again

2009-10-21 Thread Terry Reedy

Dan Guido wrote:

Hi Diez,

The source of the string literals is ConfigParser, so I can't just
mark them with an 'r'.


Python string literals only exist in Python source code. Functions and 
methods only return *strings*, not literals.  If you mistakenly put the 
str() representation of a string (such as print gives you) into source 
code, rather than the repr() output, then you may have trouble.


tjr

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


Re: which dictionary with attribute-style access?

2009-10-21 Thread Andreas Balogh
Gabriel, thanks for your hint. I've managed to create an implementation of an AttrDict 
passing Gabriels tests.


Any more comments about the pythonicness of this implementation?

class AttrDict(dict):
A dict whose items can also be accessed as member variables.
def __init__(self, *args, **kwargs):
dict.__init__(self, *args, **kwargs)
self.__dict__ = self

def copy(self):
return AttrDict(self)

def __repr__(self):
return 'AttrDict(' + dict.__repr__(self) + ')'

@classmethod
def fromkeys(self, seq, value = None):
return AttrDict(dict.fromkeys(seq, value))

--
Andreas Balogh
baloand (at) gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: a splitting headache

2009-10-21 Thread Mensanator
On Oct 21, 2:46 pm, David C Ullrich dullr...@sprynet.com wrote:
 On Tue, 20 Oct 2009 15:22:55 -0700, Mensanator wrote:
  On Oct 20, 1:51 pm, David C Ullrich dullr...@sprynet.com wrote:
  On Thu, 15 Oct 2009 18:18:09 -0700, Mensanator wrote:
   All I wanted to do is split a binary number into two lists, a list of
   blocks of consecutive ones and another list of blocks of consecutive
   zeroes.

   But no, you can't do that.

   c = '001110'
   c.split('0')
   ['', '', '1', '', '', '', '11', '']

   Ok, the consecutive delimiters appear as empty strings for reasons
   unknown (except for the first one). Except when they start or end the
   string in which case the first one is included.

   Maybe there's a reason for this inconsistent behaviour but you won't
   find it in the documentation.

  Wanna bet? I'm not sure whether you're claiming that the behavior is
  not specified in the docs or the reason for it. The behavior certainly
  is specified. I conjecture you think the behavior itself is not
  specified,

  The problem is that the docs give a single example

  '1,,2'.split(',')
  ['1','','2']

  ignoring the special case of leading/trailing delimiters. Yes, if you
  think it through, ',1,,2,'.split(',') should return ['','1','','2','']
  for exactly the reasons you give.

  Trouble is, we often find ourselves doing ' 1  2  '.split() which
  returns
  ['1','2'].

  I'm not saying either behaviour is wrong, it's just not obvious that the
  one behaviour doesn't follow from the other and the documentation could
  be
  a little clearer on this matter. It might make a bit more sense to
  actually
  mention the slpit(sep) behavior that split() doesn't do.

 Have you _read_ the docs?

Yes.

 They're quite clear on the difference
 between no sep (or sep=None) and sep=something:

I disagree that they are quite clear. The first paragraph makes no
mention of leading or trailing delimiters and they show no example
of such usage. An example would at least force me to think about it
if it isn't specifically mentioned in the paragraph.

One could infer from the second paragraph that, as it doesn't return
empty stings from leading and trailing whitespace, slpit(sep) does
for leading/trailing delimiters. Of course, why would I even be
reading
this paragraph when I'm trying to understand split(sep)?

The splitting of real strings is just as important, if not more so,
than the behaviour of splitting empty strings. Especially when the
behaviour is radically different.

 '01110'.split('0')
['', '1', '', '', '', '11', '']

is a perfect example. It shows the empty strings generated from the
leading and trailing delimiters, and also that you get 3 empty
strings
between the '1's, not 4. When creating documentation, it is always a
good idea to document such cases.

And you'll then want to compare this to the equivalent whitespace
case:
 ' 111 '.split()
['1', '11']

And it wouldn't hurt to point this out:
 c = '01110'.split('0')
 '0'.join(c)
'01110'

and note that it won't work with the whitespace version.

No, I have not submitted a request to change the documentation, I was
looking for some feedback here. And it seems that no one else
considers
the documentation wanting.


 If sep is given, consecutive delimiters are not grouped together and are
 deemed to delimit empty strings (for example, '1,,2'.split(',') returns
 ['1', '', '2']). The sep argument may consist of multiple characters (for
 example, '123'.split('') returns ['1', '2', '3']). Splitting an
 empty string with a specified separator returns [''].

 If sep is not specified or is None, a different splitting algorithm is
 applied: runs of consecutive whitespace are regarded as a single
 separator, and the result will contain no empty strings at the start or
 end if the string has leading or trailing whitespace. Consequently,
 splitting an empty string or a string consisting of just whitespace with
 a None separator returns [].





  because your description of what's happening,

  consecutive delimiters appear as empty strings for reasons

   unknown (except for the first one). Except when they start or end the
   string in which case the first one is included

  is at best an awkward way to look at it. The delimiters are not
  appearing as empty strings.

  You're asking to split  '001110' on '0'. So you're asking for
  strings a, b, c, etc such that

  (*) '001110' = a + '0' + b + '0' + c + '0' + etc

  The sequence of strings you're getting as output satisfies (*) exactly;
  the first '' is what appears before the first delimiter, the second ''
  is what's between the first and second delimiters, etc.

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


Re: The rap against while True: loops

2009-10-21 Thread Jorgen Grahn
On Wed, 2009-10-14, Steven D'Aprano wrote:
...

 Setting up a try...except block is cheap in Python. According to my 
 tests, the overhead is little more than that of a single pass statement.

 But actually raising and catching the exception is not cheap. If you use 
 a lot of exceptions for flow control, performance will probably suffer.

You seem to have experimented with this, so you might be right.

 In C++, exceptions are expensive, whether you catch one or not.

I am not sure that is objectively true, even if you consider that
expensive among C++ users often means costs more than a semi-decent
alternative.  For example, Stroustrup claimed back in 1994 that the
non-catching case can be implemented at no speed cost or no memory
usage cost (Design and Evolution of C++, 1994, p397).

/Jorgen

-- 
  // Jorgen Grahn grahn@  Oo  o.   .  .
\X/ snipabacken.se   O  o   .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a simple unicode question

2009-10-21 Thread Terry Reedy

Nobody wrote:


Just curious, why did you choose to set the upper boundary at 0x?


Characters outside the 16-bit range aren't supported on all builds. They
won't be supported on most Windows builds, as Windows uses 16-bit Unicode
extensively:

Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit 
(Intel)] on
win32
 unichr(0x1)
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: unichr() arg not in range(0x1) (narrow Python build)


In Python 3, if not 2.6, chr(0x1) (what used to be unichr()) works 
fine on Windows, and generates the appropriate surrogate pair.


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


Re: How to schedule system calls with Python

2009-10-21 Thread Jorgen Grahn
On Thu, 2009-10-15, TerryP wrote:
...
 launching external programs, irregardless of language, generally falls
 into 3 major categories:

   0.) blocks until program is done; like system
   1.) replaces your program with process, never returns; like exec
   2.) quickly return after asynchronously launching the program

 Most languages will implement the first method because of the standard
 system() function in C, which is fairly popular in it's own right.
 Most multi-tasking operating systems will implement some form of exec
 function, which Python exposes through the os module. The last method
 is the least portable, because obviously if the OS lacks multi-tasking
 you're screwed. The best examples of 2. are the UNIX popen() function
 and Microsoft's spawn() family, when used with the P_DETACH flag.

Not sure that popen() fits nicely into that category -- you have to
eat the child's output or feed it with input, or it will eventually
stall.

 Python being made with much loving kindless, exposes each interface.

Nicely put!

/Jorgen

-- 
  // Jorgen Grahn grahn@  Oo  o.   .  .
\X/ snipabacken.se   O  o   .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to schedule system calls with Python

2009-10-21 Thread Jorgen Grahn
On Fri, 2009-10-16, Jeremy wrote:
 On Oct 15, 6:32 pm, MRAB pyt...@mrabarnett.plus.com wrote:
 TerryP wrote:
  On Oct 15, 7:42 pm, Jeremy jlcon...@gmail.com wrote:
  I need to write a Python script that will call some command line
  programs (using os.system).  I will have many such calls, but I want
  to control when the calls are made.  I won't know in advance how long
  each program will run and I don't want to have 10 programs running
  when I only have one or two processors.  I want to run one at a time
  (or two if I have two processors), wait until it's finished, and then
  call the next one.
...
 You could use multithreading: put the commands into a queue; start the
 same number of worker threads as there are processors; each worker
 thread repeatedly gets a command from the queue and then runs it using
 os.system(); if a worker thread finds that the queue is empty when it
 tries to get a command, then it terminates.

 Yes, this is it.  If I have a list of strings which are system
 commands, this seems like a more intelligent way of approaching it.
 My previous response will work, but won't take advantage of multiple
 cpus/cores in a machine without some manual manipulation.  I like this
 idea.

Note that you do not need *need* multithreading for this. To me it
seems silly to have N threads sitting just waiting for one process
each to die -- those threads contribute nothing to the multiprocessing
you want.

In Unix, you can have one process fork() and exec() as many programs
as you like, have them run on whatever CPUs you have, and wait for
them to die and reap them using wait() and related calls.  (Not sure
what the equivalent is in non-Unix OSes or portable Python.)

/Jorgen

-- 
  // Jorgen Grahn grahn@  Oo  o.   .  .
\X/ snipabacken.se   O  o   .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows file paths, again

2009-10-21 Thread Jerry Hill
On Wed, Oct 21, 2009 at 5:40 PM, Dan Guido dgu...@gmail.com wrote:
 This doesn't give me quite the results I expected, so I'll have to
 take a closer look at my project as a whole tomorrow. The test cases
 clearly show the need for all the fancy parsing I'm doing on the path
 though.

To get back to what I think was your original question, there is an
easy way to take a string with control characters and turn it back
into a string with the control characters escaped, which could replace
your escape_dict and raw() function in normalize.py:

 s = 'Foo\t\n\n\x12Bar'
 print s
Foo 

Bar
 r = s.encode('string-escape')
 print r
Foo\t\n\n\x12Bar


(Python 2.6.1 on windows XP)

More generally, it sounds like you have some bad data in either the
registry, or your ini file.  You shouldn't have control characters in
there (unless you really have directories with control characters in
their names).  If you have control over how those values are written,
you should probably fix the bad data at the source instead of fixing
it as you pull it back in.

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


Re: md5 strange error

2009-10-21 Thread Stephen Fairchild
Tim Golden wrote:

 catalinf...@gmail.com wrote:
 I have this error , what happen ?
 
 Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38)
 [GCC 4.3.2 20080917 (Red Hat 4.3.2-4)] on linux2
 Type help, copyright, credits or license for more information.
 import md5
 pass = md5.new()
   File stdin, line 1
 pass = md5.new()
  ^
 SyntaxError: invalid syntax
 
 pass is a keyword, as in:
 
 def f ():
   pass
 

Correct form when you want to use a keyword for a variable is to precede it
with and underscore.

_pass = md5.new() 

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


Re: md5 strange error

2009-10-21 Thread Rhodri James
On Wed, 21 Oct 2009 23:28:24 +0100, Stephen Fairchild  
someb...@somewhere.com wrote:



Tim Golden wrote:


catalinf...@gmail.com wrote:

I have this error , what happen ?

Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38)
[GCC 4.3.2 20080917 (Red Hat 4.3.2-4)] on linux2
Type help, copyright, credits or license for more information.

import md5
pass = md5.new()

  File stdin, line 1
pass = md5.new()
 ^
SyntaxError: invalid syntax


pass is a keyword, as in:

def f ():
  pass



Correct form when you want to use a keyword for a variable is to precede  
it

with and underscore.

_pass = md5.new()


Other way round; you put the underscore at the end according to PEP-8
(http://www.python.org/dev/peps/pep-0008/)

pass_ = md5.new()

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: Spam reported

2009-10-21 Thread Peter Pearson
On Wed, 21 Oct 2009 09:06:50 +1100, Ben Finney wrote:
 Grant Edwards inva...@invalid.invalid writes:
 On 2009-10-20, Peter Pearson ppear...@nowhere.invalid wrote:

  Reported to Google's groups-abuse.

 What are these postings supposed to mean?

 That the posting which started the thread (which you may or may not have
 seen, so it's good that Peter isn't quoting the original spam) has been
 reported to Google as an abuse of their service; so that others don't
 duplicate that effort.


Hmmm.  It didn't occur to me that my posts would be seen by
people to whom the spam posts were invisible.  That must indeed
look strange.

-- 
To email me, substitute nowhere-spamcop, invalid-net.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode again ... default codec ...

2009-10-21 Thread Gabriel Genellina

En Wed, 21 Oct 2009 06:24:55 -0300, Lele Gaifax l...@metapensiero.it
escribió:


Gabriel Genellina gagsl-...@yahoo.com.ar writes:


DON'T do that. Really. Changing the default encoding is a horrible,
horrible hack and causes a lot of problems.
...
More reasons:
http://tarekziade.wordpress.com/2008/01/08/syssetdefaultencoding-is-evil/
See also this recent thread in python-dev:
http://comments.gmane.org/gmane.comp.python.devel/106134


This is a problem that appears quite often, against which I have yet to
see a general workaround, or even a safe pattern. I must confess that
most often I just give up and change the if 0: line in
sitecustomize.py to enable a reasonable default...

A week ago I met another incarnation of the problem that I finally
solved by reloading the sys module, a very ugly way, don't tell me, and
I really would like to know a better way of doing it.

The case is simple enough: a unit test started failing miserably, with a
really strange traceback, and a quick pdb session revealed that the
culprit was nosetest, when it prints out the name of the test, using
some variant of print testfunc.__doc__: since the latter happened to
be a unicode string containing some accented letters, that piece of
nosetest's code raised an encoding error, that went untrapped...

I tried to understand the issue, until I found that I was inside a fresh
new virtualenv with python 2.6 and the sitecustomize wasn't even
there. So, even if my shell environ was UTF-8 (the system being a Ubuntu
Jaunty), within that virtualenv Python's stdout encoding was
'ascii'. Rightly so, nosetest failed to encode the accented letters to
that.


That seems to imply that in your normal environment you altered the
default encoding to utf-8 -- if so: don't do that!


I could just rephrase the test __doc__, or remove it, but to avoid
future noise I decided to go with the deprecated reload(sys) trick,
done as early as possible... damn, it's just a test suite after all!

Is there a correct way of dealing with this? What should nosetest
eventually do to initialize it's sys.output.encoding reflecting the
system's settings? And on the user side, how could I otherwise fix it (I
mean, without resorting to the reload())?


nosetest should do nothing special. You should configure the environment
so Python *knows* that your console understands utf-8. Once Python is
aware of the *real* encoding your console is using, sys.stdout.encoding
will be utf-8 automatically and your problem is solved. I don't know how
to do that within virtualenv, but the answer certainly does NOT involve
sys.setdefaultencoding()

On Windows, a normal console window on my system uses cp850:


D:\USERDATA\Gabrielchcp
Tabla de códigos activa: 850

D:\USERDATA\Gabrielpython
Python 2.6.3 (r263rc1:75186, Oct  2 2009, 20:40:30) [MSC v.1500 32 bit
(Intel)]
on win32
Type help, copyright, credits or license for more information.
py import sys
py sys.getdefaultencoding()
'ascii'
py sys.stdout.encoding
'cp850'
py u = uáñç
py print u
áñç
py u
u'\xe1\xf1\xe7'
py u.encode(cp850)
'\xa0\xa4\x87'
py import unicodedata
py unicodedata.name(u[0])
'LATIN SMALL LETTER A WITH ACUTE'

I opened another console, changed the code page to 1252 (the one used in
Windows applications; `chcp 1252`) and invoked Python again:

py import sys
py sys.getdefaultencoding()
'ascii'
py sys.stdout.encoding
'cp1252'
py u = uáñç
py print u
áñç
py u
u'\xe1\xf1\xe7'
py u.encode(cp1252)
'\xe1\xf1\xe7'
py import unicodedata
py unicodedata.name(u[0])
'LATIN SMALL LETTER A WITH ACUTE'

As you can see, everything works fine without any need to change the
default encoding... Just make sure Python *knows* which encoding is being
used in the console on which it runs. On Ubuntu you may need to set the
LANG environment variable.

--
Gabriel Genellina

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


Re: How to schedule system calls with Python

2009-10-21 Thread Al Fansome



Jorgen Grahn wrote:

On Fri, 2009-10-16, Jeremy wrote:

On Oct 15, 6:32 pm, MRAB pyt...@mrabarnett.plus.com wrote:

TerryP wrote:

On Oct 15, 7:42 pm, Jeremy jlcon...@gmail.com wrote:

I need to write a Python script that will call some command line
programs (using os.system).  I will have many such calls, but I want
to control when the calls are made.  I won't know in advance how long
each program will run and I don't want to have 10 programs running
when I only have one or two processors.  I want to run one at a time
(or two if I have two processors), wait until it's finished, and then
call the next one.

...

You could use multithreading: put the commands into a queue; start the
same number of worker threads as there are processors; each worker
thread repeatedly gets a command from the queue and then runs it using
os.system(); if a worker thread finds that the queue is empty when it
tries to get a command, then it terminates.

Yes, this is it.  If I have a list of strings which are system
commands, this seems like a more intelligent way of approaching it.
My previous response will work, but won't take advantage of multiple
cpus/cores in a machine without some manual manipulation.  I like this
idea.


Note that you do not need *need* multithreading for this. To me it
seems silly to have N threads sitting just waiting for one process
each to die -- those threads contribute nothing to the multiprocessing
you want.

In Unix, you can have one process fork() and exec() as many programs
as you like, have them run on whatever CPUs you have, and wait for
them to die and reap them using wait() and related calls.  (Not sure
what the equivalent is in non-Unix OSes or portable Python.)

/Jorgen



Another way to approach this, if you do want to use threads, is to use a 
counting semaphore. Set it to the maximum number of threads you want to 
run at any one time. Then loop starting up worker threads in the main 
thread. acquire() the semaphore before starting the next worker thread; 
when the semaphore reaches 0, your main thread will block. Each worker 
thread should then release() the semaphore when it  exits; this will 
allow the main thread to move on to creating the next worker thread.


This doesn't address the assignment of threads to CPU cores, but I have 
used this technique many times, and it is simple and fairly easy to 
implement. You have to make sure, though, that you catch all exceptions 
in the worker threads; if a thread exits without releasing the 
semaphore, you will have a semaphore leak. And, of course, there are 
subtleties concerning threading that you always have to worry about, 
such as using a mutex, for instance, around any print statements so the 
various thread outputs don't mess each other up.

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


Re: mysql select some sort of caching

2009-10-21 Thread David Sfiligoi
On Wed, 21 Oct 2009 00:45:21 -0300, Gabriel Genellina wrote:
 
 If you want to keep the cursor open, you must commit the (implicit)
 current transaction, even if it only contains selects (a rollback would
 work too).
 Alternatively, lower the transaction isolation level below repeatable
 reads. Note that in other scenarios, ensuring that the same query
 returns the same results is a Good Thing.

Thanks Gabriel,  I tried the commit suggestion and it works.  I was 
thinking that everytime I made a select query and if the data changed 
between the select query(like anohter application updating a field and 
commiting the transaction), the select query routing inside the database 
engine would recognised that the data is no longer the same as the 
previous exact same query and would return me the new data.

David

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


python, emacs, pylint, epylint, flymake

2009-10-21 Thread Richard Riley

I have asked in emacs help too, but basically does anyone here have
pylint integrated with emacs so that you can actually read the error
description? I am set up as described here:-

http://tinyurl.com/yfshb5b

or

http://stackoverflow.com/questions/1259873/how-can-i-use-emacs-flymake-mode-for-python-with-pyflakes-and-pylint-checking-cod

my buffer has erroneous lines hilited but there is no context help to
actually tell me what the error is. I dont know if this is an error
specific to emacs 23. (Debian).

Thanks for any info, help you can give me.

regards

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


How to write a facebook client?

2009-10-21 Thread holmes86
Hi,everyone

I'm a python newbie,and I want to write a facebook client.But I don't
know how to do it.Meanwhile I have any write web experience,so I also
don't know how to analyse web page.Any help will be appreciate.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt4 - remember widget positions

2009-10-21 Thread TerryP
On Oct 21, 9:04 pm, nusch nusc...@gmail.com wrote:
 Is there any simple command which allows me to save position of all
 windows:  QMainWindow, QDialogs and qdockwidgets with their sizes,
 dock state and positions ? Or do I need to store those values
 manually, how can I do it fast?


Both fast and simple have relative meanings, there may be some common
persistence mumbo jumbo added to Qt since I last looked but, in
generally read this:

http://doc.trolltech.com/4.5/geometry.html

I don't know off the top of my head if PyQt's documentation has code
examples on it, but it should be fairly easy for you to comprehend how
to do it in Python.

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


problems on installing PyGTK in Windows XP

2009-10-21 Thread Yang
Python 2.6.3 is installed on my Windows XP throught the binary file
provided by Python.org. Then I followed the steps described here:

http://faq.pygtk.org/index.py?req=showfile=faq21.001.htp

to install PyGTK. However, I still get the following error:
 import pygtk
 pygtk.require('2.0')
 import gtk
Traceback (most recent call last):
  File stdin, line 1, in module
  File C:\Python26\lib\site-packages\gtk-2.0\gtk\__init__.py, line
48, in mod
ule
from gtk import _gtk
ImportError: DLL load failed: The specified module could not be found.

I googled this problem and noticed that there are quite a few people
having the same problem. But I am unable to find anything which helps
me solve this problem.

Could you please give me some suggestions?

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


Re: Windows file paths, again

2009-10-21 Thread Dave Angel

Dan Guido wrote:

This doesn't give me quite the results I expected, so I'll have to
take a closer look at my project as a whole tomorrow. The test cases
clearly show the need for all the fancy parsing I'm doing on the path
though.

Looks like I'll return to this tomorrow and post an update as
appropriate. Thanks for the help so far!
--
Dan Guido



On Wed, Oct 21, 2009 at 5:34 PM, Terry Reedy tjre...@udel.edu wrote:
  

Dan Guido wrote:


Hi Diez,

The source of the string literals is ConfigParser, so I can't just
mark them with an 'r'.
  

Python string literals only exist in Python source code. Functions and
methods only return *strings*, not literals.  If you mistakenly put the
str() representation of a string (such as print gives you) into source code,
rather than the repr() output, then you may have trouble.

tjr

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




For none of your test data does raw() change anything at all.  These 
strings do *not* need escaping.


Now some of the other things you do are interesting:

1) \??\   - presumably you're looking for a long UNC.  But that's 
signaled by  \\?\It's used to indicate to some functions that 
filenames over about 260 bytes are permissible.


2) The line:

   if expanded[:8] == system32 or syswow64:

doesn't do what you think it does.  it'll always evaluate as true, since 
== has higher priority and syswow64 is a non-empty string.  If you 
want to compare the string to both, you need to expand it out:


   either  if expanded[:8] == system32  or  expanded[:8] == syswow64
or simpler:
if expanded.startswith(system32) or  expanded.startswith(syswow64):

3) removing a leading backslash should imply that you replace it with 
the current directory, at least in most contexts.  I'm not sure what's 
the right thing here.




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


Re: How to write a facebook client?

2009-10-21 Thread geremy condra
On Wed, Oct 21, 2009 at 9:45 PM, holmes86 holme...@gmail.com wrote:
 Hi,everyone

 I'm a python newbie,and I want to write a facebook client.But I don't
 know how to do it.Meanwhile I have any write web experience,so I also
 don't know how to analyse web page.Any help will be appreciate.
 --
 http://mail.python.org/mailman/listinfo/python-list


Obligatory warning: any project, of any size, in computer science or
any related field, will require you to learn a *lot*, and most of the time
other people aren't going to be able or willing to help you- you just have
to do it yourself. If that doesn't sound like something you want to do
or are able to do, then you should probably save yourself some trouble
and stop now. Otherwise, the links below may be helpful.

1) google.com, it's your friend
2) htmlgoodies.com, for the basics of the web side
3) w3schools.com, for a bit more of the web stuff
4) docs.python.org, for the python stuff
5) http://wiki.developers.facebook.com/index.php/PythonPyFacebookTutorial,
for getting python and facebook to play nicely together.

Good luck.

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


Re: Fallen Sword

2009-10-21 Thread Ben Finney
Richard Riley rileyrg...@gmail.com writes:

 Ben Finney ben+pyt...@benfinney.id.au writes:
  Reported to service provider as spam.

 Please don't reply to SPAM. You just make it visible to those of us
 with better filters. Hint : spammers do not read your reply.

I didn't quote the spam except to be clear which message I'm responding
to. None of the substantive content was quoted, and the spammer's
message is thwarted.

 And no one else is really interested in your reports either.

Others who might want the message reported can know that it has already
happened. I also see it as visibly advocating, by example, the practice
of reporting each and every spam message to the service provider that
was used to send it.

-- 
 \   “He who wonders discovers that this in itself is wonder.” |
  `\  —Maurits Cornelis Escher |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fallen Sword

2009-10-21 Thread Paul Huber
On Thu, 22 Oct 2009 14:00:03 +1100, Ben Finney
ben+pyt...@benfinney.id.au wrote:

 Ben Finney ben+pyt...@benfinney.id.au writes:
  Reported to service provider as spam.

 Please don't reply to SPAM. You just make it visible to those of us
 with better filters. Hint : spammers do not read your reply.

I didn't quote the spam except to be clear which message I'm responding
to. None of the substantive content was quoted, and the spammer's
message is thwarted.

 And no one else is really interested in your reports either.

Others who might want the message reported can know that it has already
happened. I also see it as visibly advocating, by example, the practice
of reporting each and every spam message to the service provider that
was used to send it.

I also see a lot of other practices ... that does't mean they are
smart.
What Richard suggested *is* - if you wish to report spam do it in
private, you don't need to alert the whole group of your actions. I
personally am not interested in spam, and am even less interested in
people reporting spam (because usually on one spam message comes 10
report it. it doesn't belong here replies.)

Many of us have filters that have been tuned over time so that we
don't see the original spam when it appears.

By calling attention to yourself, you're indirectly just helping the
spammer suffocate the group.


Paul

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


subprocess executing shell

2009-10-21 Thread Tim Arnold
Hi, I'm writing a script to capture a command on the commandline and run it 
on a remote server.
I guess I don't understand subprocess because the code below exec's the 
user's .cshrc file even though by default shell=False in the Popen call.

Here's the code. I put a line in my .cshrc file: echo 'testing' which 
appears when I run this script on the remote host.

import os,sys,subprocess,shlex

def main():
if action:
action.insert(0,'rsh my_remotehost')
p = subprocess.Popen(shlex.split(' '.join(action)))
p.wait()

if __name__ == '__main__':
action = sys.argv[1:] or list()
main()


Since the shell is executing in the child process anyway, is the only 
difference when using shell=True is that environment variables can be 
expanded in the command to be executed?

thanks,
--Tim Arnold


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


Re: Cpython optimization

2009-10-21 Thread John Nagle

Qrees wrote:

Hello

As my Master's dissertation I chose Cpython optimization. That's why
i'd like to ask what are your suggestions what can be optimized. Well,
I know that quite a lot. I've downloaded the source code (I plan to
work on Cpython 2.6 and I've downloaded 2.6.3 release). By looking at
the code I've found comment's like this can be optimized by... etc.
but maybe you guide me what should I concentrate on in my work?

I've 6-7 month  for this and If I create something decent I can
publish it.

Thank you in advance for any help


  The Shed Skin people would welcome some help.

http://shed-skin.blogspot.com/

Shed Skin is a Python to C++ compiler with automatic type inference.
For the programs it can handle, it's the fastest Python implementation
by a large margin.

The basic restriction in Shed Skin is that, while you don't have to
declare types, each variable generally has to stay the same type
throughout its life.  (Different subclasses of the same class are OK.)
This is enough to make huge speedups possible.

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


Re: mysql select some sort of caching

2009-10-21 Thread Gabriel Genellina
En Wed, 21 Oct 2009 22:24:49 -0300, David Sfiligoi sfili...@gmail.com  
escribió:



On Wed, 21 Oct 2009 00:45:21 -0300, Gabriel Genellina wrote:


If you want to keep the cursor open, you must commit the (implicit)
current transaction, even if it only contains selects (a rollback would
work too).
Alternatively, lower the transaction isolation level below repeatable
reads. Note that in other scenarios, ensuring that the same query
returns the same results is a Good Thing.


Thanks Gabriel,  I tried the commit suggestion and it works.  I was
thinking that everytime I made a select query and if the data changed
between the select query(like anohter application updating a field and
commiting the transaction), the select query routing inside the database
engine would recognised that the data is no longer the same as the
previous exact same query and would return me the new data.


Yes, this is known as phantom read, and may happen depending on the  
transaction isolation level currently in effect.  Although in your use  
case it may be a desirable feature, in other cases it's not. See  
http://en.wikipedia.org/wiki/Isolation_(database_systems)


--
Gabriel Genellina

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


  1   2   >