reg: playing with the list

2011-06-24 Thread kaustubh joshi
Hey all,
I am new here and new to python too. In general new to programming .
I was working on aproblem.
and need some help.
I have a list of numbers say [2,3,5,6,10,15]
which all divide number 30.
Now i have to reduce this list to the numbers which are prime in number.
i.e.
[2,3,5]
can somebody suggest?
K
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: search through this list's email archives

2011-06-24 Thread Gabriel Genellina
En Thu, 23 Jun 2011 13:11:32 -0300, Cathy James   
escribió:



I looked through this forum's archives, but I can't find a way to
search for a topic through the archive. Am I missing something?



Gmane provides a search capability also:
http://blog.gmane.org/gmane.comp.python.general

--
Gabriel Genellina

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


Re: Interpreting Left to right?

2011-06-24 Thread Ethan Furman

Terry Reedy wrote:

On 6/24/2011 12:32 AM, Chetan Harjani wrote:

x=y="some string"
And we know that python interprets from left to right.


Read the doc. "5.14. Evaluation order
Python evaluates expressions from left to right. Notice that while 
evaluating an assignment, the right-hand side is evaluated before the 
left-hand side."


The example given to me when I had this question:

--> x = x['huh'] = {}
--> x
{'huh': {...}}


As you can see, the creation of the dictionary is evaluated, and bound 
to the name 'x'; then the key 'huh' is set to the same dictionary.  If 
you try that the other way 'round this happens:


>>> x['huh'] = x = {}
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'x' is not defined

So -- the RHS (right hand side) gets evaluated first, then the LHSs from 
left to right.


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


Re: User Authentication

2011-06-24 Thread Michael Ströder
Anurag wrote:
> My application is a web based application for both windows and Linux.
> The web part is developed using Django. So if Python does not support
> it then any support for local sytem account authentication in Django?
> 
> I am looking for a common library for both Linux and Windows. Any help
> will be Gr8

Doesn't Django provide an abstraction layer for accessing differnt
authentication backends? I guess you have to write/use two different
authentication modules for the two different mechanisms.

A quick search looks promising:

http://www.google.com/search?q=django+ldap+authentication

Ciao, Michael.
-- 
http://mail.python.org/mailman/listinfo/python-list


Looking PDF module

2011-06-24 Thread Hegedüs Ervin
Hello Everyone,

I'm looking a good PDF module for Python 2.x - I've never used
any PDF in Python, I don't know, what would be a good choice.

There are several PDF tool for Python - this is my problem :)

What I need:
- utf8 support
- create header and footer
- (in headers there are small images)
- tables
- left and right side handling (this will be a book)
- various page numbering (eg.: I/1, I/2, ... or simple numeric
  form)
- TOC generating


Any help would comes well,

thanks:


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


Re: Mac OS X 10.6.6 and MacPyhton 2.6 idle doesn't work

2011-06-24 Thread mando
I took MacPython 2.6 from here:

http://www.python.org/ftp/python/2.6.6/python-2.6.6-macosx10.3.dmg


Also I downloaded Tcl/Tk from here http://www.kyngchaos.com/software/frameworks
to using the gis software Qgis

May be here the issue?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.7 and cmd on Windows 7 64 (files lost)

2011-06-24 Thread Martin v. Loewis
> Therefore, Windows has a "trick" for mark the file like visible, or not,
> in 32 mode. What trick?

It's called file system redirection. When you access \windows\system32
in a 32-bit process, you *actually* access \windows\syswow64, which
has entirely different files.

The same also happens for parts of the registry.

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


Re: Looking PDF module

2011-06-24 Thread mando
Take a look to reportlab:

http://www.reportlab.com/software/opensource/

Bye bye

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


Re: Interpreting Left to right?

2011-06-24 Thread Chris Angelico
On Fri, Jun 24, 2011 at 5:14 PM, Ethan Furman  wrote:
> --> x = x['huh'] = {}
> --> x
> {'huh': {...}}
>

I would have to call that dodgy practice... unless you have a lot of
places where you need a dictionary with itself as an element, I would
avoid assignments that depend on each other.

Perhaps it's just because I'm a C programmer, but that code smells a
lot like the classic "i = i++;" blunder - nearly as bad as land wars
in Asia.

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


Re: those darn exceptions

2011-06-24 Thread Gregory Ewing

Chris Torek wrote:

I can then check the now-valid
pid via os.kill().  However, it turns out that one form of "trash"
is a pid that does not fit within sys.maxint.  This was a surprise
that turned up only in testing, and even then, only because I
happened to try a ridiculously large value as one of my test cases.


It appears that this situation is not unique to os.kill(),
for example,

>>> import os
>>> os.read(, 42)
Traceback (most recent call last):
  File "", line 1, in 
OverflowError: Python int too large to convert to C long

In fact I'd expect it to happen any time you pass a
very large int to something that's wrapping a C function.

You can't really blame the wrappers for this -- it's not
reasonable to expect all of them to catch out-of-range ints
and do whatever the underlying function would have done if
it were given an invalid argument.

I think the lesson to take from this is that you should
probably add OverflowError to the list of things to catch
whenever you're calling a function with input that's not
fully validated.

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


how to write to registry without admin rights on win vista/7

2011-06-24 Thread miamia
Hello,

In my program I can set to run after system startup (it writes path to
Software\Microsoft\Windows\CurrentVersion\Run) but when normal user is
logged in my application crashes. I must right click on app an choose
"Run As Admin" and then everything works.

How can I do it to write to registry without "Run As Admin" ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking PDF module

2011-06-24 Thread Hegedüs Ervin
hello,

On Fri, Jun 24, 2011 at 12:37:40AM -0700, mando wrote:
> Take a look to reportlab:
> 
> http://www.reportlab.com/software/opensource/

thanks, I'll check it out,


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


Re: Interpreting Left to right?

2011-06-24 Thread Chetan Harjani
Now its all clear. Thanks
@ethan .. ur example is really scary.
I didnt understand ur example fully although.
See this is what i take it as:
x=x['huh']={}

>first python checks check that there are two = operators.
>so it evaluates the RHS(since for = it is RHS to LHS) experession of right
most (why is that?)
>now it assigns that experrsion({...}) to x the left most as u said first
RHS to LHS then LHS to RHS.
>then it assigns x to to x['huh'].
huh!!, ryt?
may be it doesnt make sense but i guess this is the only way to actually not
raise an error.

Where am I wrong?





On Fri, Jun 24, 2011 at 10:02 AM, Chetan Harjani
wrote:

> x=y="some string"
> And we know that python interprets from left to right. so why it doesnt
> raise a name error here saying name 'y' is not defined?
>
> another example:
> (1,2) + 3,
> here, python raises a  TypeError "can only concatenate tuple(not int) to
> tuple" but we know (3,) is a tuple as seen by following:
> t=3,
> type(t)
> 
> Arent both of this contradicting?
>
> --
> Chetan H Harjani
>
>


-- 
Chetan H Harjani
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to write to registry without admin rights on win vista/7

2011-06-24 Thread Duncan Booth
miamia  wrote:

> Hello,
> 
> In my program I can set to run after system startup (it writes path to
> Software\Microsoft\Windows\CurrentVersion\Run) but when normal user is
> logged in my application crashes. I must right click on app an choose
> "Run As Admin" and then everything works.
> 
> How can I do it to write to registry without "Run As Admin" ?

This might give you some pointers:

http://stackoverflow.com/questions/130763/request-uac-elevation-from-within-a-python-script


-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: LDAP: How get all users belongs to a group.

2011-06-24 Thread Michael Ströder
sajuptpm wrote:
> How get all users belongs to a group using python ldap module.

There are several ways of storing grouping information in a LDAP server.

I assume the groups are normal group entries of object class 'groupOfNames'
which is most commonly used. Such an entry has the attribute 'member' which
contains DNs of all member entries which you would have to read yourself. This
can be quite annoying for large group entries since you would have to send a
search request for each group member.

Therefore on some servers you can search for a back-link attribute in the user
entries. Most times it's called 'memberOf' or 'isMemberOf'. But this depends
on the server's implemented features and configuration.

Which LDAP server are you using?

Ciao, Michael.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: LDAP: How get all users belongs to a group.

2011-06-24 Thread sajuptpm
Hi,
Thanks for reply.

dn: cn=My-Group-1, ou=Groups, o=CUST
equivalentToMe: cn=TDS7034,ou=Internal PCA,o=CUST
objectClass: groupOfNames  <
objectClass: top
objectClass: swarePointers
ACL: 2#entry#[Root]#member
cn: My-Group-1
member: cn=AJP2203,ou=Internal PCA,o=CUST
member: cn=AZE9632,ou=Internal PCA,o=CUST
member: cn=BTC4979,ou=Internal PCA,o=CUST


* I have group definition in LDAP server as above.
* How fetch all members from this perticular group 'My-Group-1' using
python-ldap module.
* I tried, but i don't know how do it.
* I want to get those 3 members from group 'My-Group-'



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


Re: LDAP: How get all users belongs to a group.

2011-06-24 Thread sajuptpm
I am using Openldap (openldap 2.3.43-12.el5_5.2  and openldap.i386
0:2.3.43_2.2.29-12.el5_6.7)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question regarding DNS resolution in urllib2

2011-06-24 Thread saurabh verma

Michael Hrivnak wrote:

The latest libcurl includes the CURLOPTS_RESOLVE option
(http://curl.haxx.se/libcurl/c/curl_easy_setopt.html) that will do
what you want.  It may not have made its way into pycurl yet, but you
could just call the command-line curl binary with the --resolve
option.  This feature was introduced in version 7.21.3.

Michael
  


Hey Michael , Thanks for the response . Thats exactly what i was looking 
for.


"curl binary with the --resolve" ?

--(0)> curl --resolve
curl: option --resolve: is unknown
curl: try 'curl --help' or 'curl --manual' for more information
--(saurabhve@sa-mac-saurabh)-(~)--
--(2)> curl -V
curl 7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l 
zlib/1.2.3



Couldn't find it .

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


Want to build an app for linux

2011-06-24 Thread saurabh verma

Hi all ,

May be I'm just asking a silly/old question .

I have some open web APIs which i can use , on it  I want to develop an 
desktop application , probably cross platform but mostly I'm aiming at 
*unix platforms . 

I've got no experience in programming desktop application , but thats 
not a issue , I can do it . But i need to know right technology stack i 
could thinking of using. python or may be java or python/QT or google 
chrome platform.


May be someone can suggest me some online tutorials/references , or any 
help appreciated.


Thanks in advance 


~saurabh


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


Re: LDAP: How get all users belongs to a group.

2011-06-24 Thread sajuptpm
--- User

cn=AJP2203,ou=Internal PCA,o=CUST has group memberships
to the following Groups:
groupMembership: cn=My-Group-1,ou=Groups,o=CUST
groupMembership: cn=My-Group-2,u=Groups,o=CUST
groupMembership: cn=My-Group-3,ou=Groups,o=CUST

--- Group

dn: cn=My-Group-1, ou=Groups, o=CUST
equivalentToMe: cn=TDS7034,ou=Internal PCA,o=CUST
objectClass: groupOfNames  <
objectClass: top
objectClass: swarePointers
ACL: 2#entry#[Root]#member
cn: My-Group-1
member: cn=AJP2203,ou=Internal PCA,o=CUST
member: cn=AZE9632,ou=Internal PCA,o=CUST
member: cn=BTC4979,ou=Internal PCA,o=CUST

-

* We will get groups of a member from member record, using key
'groupMembership'.
* But i want to get members belogs to a particular group Eg:'My-
Group-1'
* Have any method in python-ldap model for this ???
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Want to build an app for linux

2011-06-24 Thread Adam Tauno Williams
On Fri, 2011-06-24 at 15:55 +0530, saurabh verma wrote:
> Hi all ,
> May be I'm just asking a silly/old question .
> I have some open web APIs which i can use , on it  I want to develop an 
> desktop application , probably cross platform but mostly I'm aiming at 
> *unix platforms . 
> I've got no experience in programming desktop application , but thats 
> not a issue , I can do it . But i need to know right technology stack i 
> could thinking of using. python or may be java or python/QT or google 
> chrome platform.
> May be someone can suggest me some online tutorials/references , or any 
> help appreciated.

I've found Python + Gtk (which includes Glade) to be a very productive
solution.



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


Re: Want to build an app for linux

2011-06-24 Thread saurabh verma

Adam Tauno Williams wrote:

On Fri, 2011-06-24 at 15:55 +0530, saurabh verma wrote:
  

Hi all ,
May be I'm just asking a silly/old question .
I have some open web APIs which i can use , on it  I want to develop an 
desktop application , probably cross platform but mostly I'm aiming at 
*unix platforms . 
I've got no experience in programming desktop application , but thats 
not a issue , I can do it . But i need to know right technology stack i 
could thinking of using. python or may be java or python/QT or google 
chrome platform.
May be someone can suggest me some online tutorials/references , or any 
help appreciated.



I've found Python + Gtk (which includes Glade) to be a very productive
solution.



  

Hmm thanks for the response adam , I'll definitely check it out.

Quick question : Is creating jazzy UI feasible with python + gtk ? like 
round shaped corners , color schemes etc etc.


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


Re: LDAP: How get all users belongs to a group.

2011-06-24 Thread Michael Ströder
sajuptpm wrote:
> --- User
> 
> cn=AJP2203,ou=Internal PCA,o=CUST has group memberships
> to the following Groups:
> groupMembership: cn=My-Group-1,ou=Groups,o=CUST
> groupMembership: cn=My-Group-2,u=Groups,o=CUST
> groupMembership: cn=My-Group-3,ou=Groups,o=CUST
> 
> --- Group
> 
> dn: cn=My-Group-1, ou=Groups, o=CUST
> equivalentToMe: cn=TDS7034,ou=Internal PCA,o=CUST
> objectClass: groupOfNames  <
> objectClass: top
> objectClass: swarePointers
> ACL: 2#entry#[Root]#member
> cn: My-Group-1
> member: cn=AJP2203,ou=Internal PCA,o=CUST
> member: cn=AZE9632,ou=Internal PCA,o=CUST
> member: cn=BTC4979,ou=Internal PCA,o=CUST
> 
> -
> 
> * We will get groups of a member from member record, using key
> 'groupMembership'.
> * But i want to get members belogs to a particular group Eg:'My-
> Group-1'

If this is the server's data the LDAP server seems to be Novell eDirectory not
OpenLDAP.

I'd try member search with this filter:

  (groupMembership=cn=My-Group-1,ou=Groups,o=CUST)

Ciao, Michael.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Want to build an app for linux

2011-06-24 Thread saurabh verma
On Fri, Jun 24, 2011 at 4:24 PM, Anthony Papillion wrote:

> Hi Saurabh,
>
> I'm an experienced developer with quite a few years invested in both
> desktop and web development. But up until a few weeks ago, I'd really
> never touched Python much less developed a desktop app in it.
>
> I can tell you that the absolute easiest way to get started is this stack:
>
> PyGTK
> Glade
> Python
>
> Using those tools you'll be able to quickly learn to build desktop
> apps in Python with *very* little stress.
>
> Hope this helps and welcome to the list!
>
>
> hey anthony thanks for the help , Yes its definitely helpful . I have got
two recommendations for pygtk/glade :)  . I surely will be taking a deep
dive in it very soon.

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


Binary neural network in Python

2011-06-24 Thread Igor Begić
Hello,



I,m new in Python, I want to design and train a binary neural network
classifiers  in Python.

This model of neural network should make preprocessing expert system model
to deal with the original telecommunications alarms. *The model can be seen
as the simplest kind of feed-**forward neural network which contains three
inputs, six link **weights, two neuron and two outputs*. This model uses two
important techniques, of which the time window technique is used for
converting original alarms into transactions, and the neural network
technique can classify the alarms with different levels according to the
characteristics of telecommunication networks in order to mine the weighted
association rules.

Can anyone guide me, from where can I get some useful
material/eBook/libraries etc. for the same (maybe there is source code
already written?). I have no prior experience in neural netwoks and want to
implement it urgently.



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


Re: Project-wide variable...

2011-06-24 Thread Gnarlodious
On Jun 24, 12:27 am, Terry Reedy wrote:

> > 1) Can I tell Executable.py to share Data with ModuleTest.py?
>
> After the import is complete, yes.
> import ModuleTest
> ModuleTest.Data = Data
>
> This works if the use of Data is inside a function that is not called
> during import, not if the use of Data is at toplevel or in a class
> statement outside a def.

That works! The solution looks like this:

# controlling program:
from Module import Data
import ModuleTest
ModuleTest.Data = Data
ModuleTest.getData()

# module:
def getData():
print(Data.Plist.Structure)


Thanks for all your help!

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


Re: Looking PDF module

2011-06-24 Thread neil.suffi...@gmail.com
You might also want to have a look at Pisa ( http://www.xhtml2pdf.com/
) . It's based on reportlab but might suit you better.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Want to build an app for linux

2011-06-24 Thread J.O. Aho
Adam Tauno Williams wrote:
> On Fri, 2011-06-24 at 15:55 +0530, saurabh verma wrote:
>> Hi all ,
>> May be I'm just asking a silly/old question .
>> I have some open web APIs which i can use , on it  I want to develop an 
>> desktop application , probably cross platform but mostly I'm aiming at 
>> *unix platforms . 
>> I've got no experience in programming desktop application , but thats 
>> not a issue , I can do it . But i need to know right technology stack i 
>> could thinking of using. python or may be java or python/QT or google 
>> chrome platform.
>> May be someone can suggest me some online tutorials/references , or any 
>> help appreciated.
> 
> I've found Python + Gtk (which includes Glade) to be a very productive
> solution.
> 
> 
> 

I prefer QT and you have qt-creator:
http://qt.nokia.com/products/developer-tools
and PyQT/SIP:
http://www.riverbankcomputing.co.uk/software/pyqt/intro

IMHO you will get a better looking thing than with gtk2.

-- 

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


Re: Want to build an app for linux

2011-06-24 Thread J.O. Aho
saurabh verma wrote:

> 
> Quick question : Is creating jazzy UI feasible with python + gtk ? like
> round shaped corners , color schemes etc etc.

Button shapes and colors are generally done in themes and luckily people using
QT/gtk2 are allowed to change themes themselves which makes that the apps they
use looks as they wish and not how a dictator want them to look (mainly
thinking of mr gates and & co).


-- 

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


Re: Want to build an app for linux

2011-06-24 Thread saurabh verma



I prefer QT and you have qt-creator:
http://qt.nokia.com/products/developer-tools
and PyQT/SIP:
http://www.riverbankcomputing.co.uk/software/pyqt/intro

IMHO you will get a better looking thing than with gtk2.

  

Thanks Aho , Will surely look into it .
--
http://mail.python.org/mailman/listinfo/python-list


Re: Want to build an app for linux

2011-06-24 Thread saurabh verma

J.O. Aho wrote:

saurabh verma wrote:

  

Quick question : Is creating jazzy UI feasible with python + gtk ? like
round shaped corners , color schemes etc etc.



Button shapes and colors are generally done in themes and luckily people using
QT/gtk2 are allowed to change themes themselves which makes that the apps they
use looks as they wish and not how a dictator want them to look (mainly
thinking of mr gates and & co).


  

Thats really informative tip.

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


Re: reg: playing with the list

2011-06-24 Thread Colin J. Williams

On 24-Jun-11 03:01 AM, kaustubh joshi wrote:

Hey all,
I am new here and new to python too. In general new to programming .
I was working on aproblem.
and need some help.
I have a list of numbers say [2,3,5,6,10,15]
which all divide number 30.
Now i have to reduce this list to the numbers which are prime in number.
i.e.
[2,3,5]
can somebody suggest?
K



You might try  writing the boolean function is_prime(n) for almost any n.

There was a recent discussion on this topic.

Colin W.

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


WORK FROM HOME - EARN $15,000 WEEKLY ( PART TIME JOBS)

2011-06-24 Thread ruchikajai...@yahoo.in
WORK FROM HOME - EARN $15,000 WEEKLY ( PART TIME JOBS)

REGISTER NOW & START EARNING AT
http://www.work8home.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reg: playing with the list

2011-06-24 Thread Laurent Claessens



You might try  writing the boolean function is_prime(n) for almost any n.

There was a recent discussion on this topic.


Since the guy is "new in programming", I complete the answer, just in 
case. Using the function is_prime(n),


FIRST POSSIBILITY :

new_list=[]
for n in old_list:
   if is_prime(n):
  new_list.append(n)

SECOND POSSIBILITY :

new_list=[ n for n in old_list if is_prime(n) ]



There is a primiality test in Sage which is basically a module over 
python (www.sagemath.org).


Have a good WE
Laurent
--
http://mail.python.org/mailman/listinfo/python-list


Re: search through this list's email archives

2011-06-24 Thread Grant Edwards
On 2011-06-24, Gabriel Genellina  wrote:
> En Thu, 23 Jun 2011 13:11:32 -0300, Cathy James   
> escribi?:
>
>> I looked through this forum's archives, but I can't find a way to
>> search for a topic through the archive. Am I missing something?
>
>
> Gmane provides a search capability also:
> http://blog.gmane.org/gmane.comp.python.general

FWIW, I've found the Gmane search feature to be very unreliable.  It
often overlooks a lot of matching articles for no apparent reason.

-- 
Grant Edwards   grant.b.edwardsYow! Were these parsnips
  at   CORRECTLY MARINATED in
  gmail.comTACO SAUCE?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reg: playing with the list

2011-06-24 Thread Noah Hall
On Fri, Jun 24, 2011 at 8:01 AM, kaustubh joshi  wrote:
> Hey all,
> I am new here and new to python too. In general new to programming .
> I was working on aproblem.
> and need some help.
> I have a list of numbers say [2,3,5,6,10,15]
> which all divide number 30.
> Now i have to reduce this list to the numbers which are prime in number.
> i.e.
> [2,3,5]
> can somebody suggest?

Well, you can use a built-in function called "filter" to create a list
containing only values that meet a certain need, for example, this
will filter out everything that is even and put it into a new list -
>>> numbers = [1,2,3,4]
>>> def is_even(n):
return n%2==0 # returns true if even, false if not.

>>> filter(is_even,numbers)
[2, 4]


All you need to do is to create or adapt an algorithm that tests
whether a number is prime or not, and use that along with filter on
your list of numbers. Several examples exist, it's quite a popular
question.

HTH.

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


Re: LDAP: How get all users belongs to a group.

2011-06-24 Thread John Gordon
In <34110eed-96bc-499f-9a4e-068f2720f...@h12g2000pro.googlegroups.com> sajuptpm 
 writes:

> dn: cn=My-Group-1,ou=Groups,o=CUST
> member: cn=AJP2203,ou=Internal PCA,o=CUST
> member: cn=AZE9632,ou=Internal PCA,o=CUST
> member: cn=BTC4979,ou=Internal PCA,o=CUST

> * I have group definition in LDAP server as above.
> * How fetch all members from this perticular group 'My-Group-1' using
> python-ldap module.
> * I tried, but i don't know how do it.
> * I want to get those 3 members from group 'My-Group-'

This code should work, although I haven't tested it:

import ldap

uri = "my hostname and port"
user = "my username"
password = "my password"

ldapClient = ldap.initialize(uri)
ldapClient.set_option(ldap.OPT_REFERRALS, 0)

ldapClient.bind(user, password)

results = ldapClient.search_s("cn=My-Group-1,ou=Groups,o=CUST", ldap.SCOPE_BASE)

for result in results:
  result_dn = result[0]
  result_attrs = result[1]

  if "member" in result_attrs:
for member in result_attrs["member"]:
  print member

ldapClient.unbind_s()

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


unzip problem

2011-06-24 Thread Ahmed, Shakir
Hi,

 

I am getting following error message while unziping a .zip file. Any
help or idea is highly appreciated.

 

Error message>>>

Traceback (most recent call last):

  File "C:\Zip_Process\py\test2_new.py", line 15, in 

outfile.write(z.read(name))

IOError: (22, 'Invalid argument')

 

 

The script is here:

*

fh = open('T:\\test\\*.zip', 'rb')

z = zipfile.ZipFile(fh)

for name in z.namelist():

outfile = open(name, 'wb')

 

outfile.write(z.read(name))

print z

print outfile

outfile.close()

 

fh.close()



 

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


Re: unzip problem

2011-06-24 Thread Steven D'Aprano
On Fri, 24 Jun 2011 10:55:52 -0400, Ahmed, Shakir wrote:

> Hi,
> 
> 
>  
> I am getting following error message while unziping a .zip file. Any
> help or idea is highly appreciated.

How do you know it is when unzipping the file? Maybe it is, or maybe it 
isn't. The line giving the error has *two* IO operations, a read and a 
write. Either one could give IOError.

outfile.write(z.read(name))
IOError: (22, 'Invalid argument')

The first thing is to isolate what is causing the error:

data = z.read(name)
outfile.write(data)

Now you can be sure whether it is the read or the write  which causes the 
error.

Secondly, find out what the argument is. Assuming it is the read, try 
this:

print repr(name)

Can you open the zip file in Winzip or some other zip utility? Does it 
need a password? 

I see you do this:

fh = open('T:\\test\\*.zip', 'rb')

Do you really have a file called *.zip? I find that very hard to 
believe... as I understand it, * is a reserved character in Windows and 
you cannot have a file with that name.

My guess is that the actual error is when you try to open the file in the 
first place, before any unzipping takes place, but you've messed up the 
line numbers (probably by editing the file after importing it).


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


Re: unzip problem

2011-06-24 Thread Philip Semanchuk

On Jun 24, 2011, at 10:55 AM, Ahmed, Shakir wrote:

> Hi,
> 
> 
> 
> I am getting following error message while unziping a .zip file. Any
> help or idea is highly appreciated.
> 
> 
> 
> Error message>>>
> 
> Traceback (most recent call last):
> 
>  File "C:\Zip_Process\py\test2_new.py", line 15, in 
> 
>outfile.write(z.read(name))
> 
> IOError: (22, 'Invalid argument')


Start debugging with these two steps --
1) Add this just after "for name in z.namelist():"
   print name

That way you can tell which file is failing.

2) You can't tell whether you're getting an error on the write or the read 
because you've got two statements combined into one line. Change this --
   outfile.write(z.read(name))
to this --
   data = z.read(name)
   outfile.write(data)


Good luck
Philip


> 
> 
> 
> 
> 
> The script is here:
> 
> *
> 
> fh = open('T:\\test\\*.zip', 'rb')
> 
> z = zipfile.ZipFile(fh)
> 
> for name in z.namelist():
> 
>outfile = open(name, 'wb')
> 
> 
> 
>outfile.write(z.read(name))
> 
>print z
> 
>print outfile
> 
>outfile.close()
> 
> 
> 
> fh.close()
> 
> 
> 
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


Re: Looking PDF module

2011-06-24 Thread Cameron Laird
On Jun 24, 6:45 am, "neil.suffi...@gmail.com"
 wrote:
> You might also want to have a look at Pisa (http://www.xhtml2pdf.com/
> ) . It's based on reportlab but might suit you better.

There's more to the story.  As with many things, the answer is, "it
depends".
In this case, there are so many variables that I probably should write
up an
article outlining the pertinent ones ...

Hegedüs Ervin, it's quite likely that ReportLab will be a good
technical fit
for you.  Are you in a position to pay licensing fees for advanced
features?
Do you have any requirements to *merge* PDF instances?  How stringent
are your
performance requirements?
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: unzip problem

2011-06-24 Thread Ahmed, Shakir
On Fri, 24 Jun 2011 10:55:52 -0400, Ahmed, Shakir wrote:

> Hi,
> 
> 
>  
> I am getting following error message while unziping a .zip file. Any
> help or idea is highly appreciated.

How do you know it is when unzipping the file? Maybe it is, or maybe it 
isn't. The line giving the error has *two* IO operations, a read and a 
write. Either one could give IOError.

outfile.write(z.read(name))
IOError: (22, 'Invalid argument')

The first thing is to isolate what is causing the error:

data = z.read(name)
outfile.write(data)

Now you can be sure whether it is the read or the write  which causes
the 
error.

Secondly, find out what the argument is. Assuming it is the read, try 
this:

print repr(name)

Can you open the zip file in Winzip or some other zip utility? Does it 
need a password? 

I see you do this:

fh = open('T:\\test\\*.zip', 'rb')

Do you really have a file called *.zip? I find that very hard to 
believe... as I understand it, * is a reserved character in Windows and 
you cannot have a file with that name.

My guess is that the actual error is when you try to open the file in
the 
first place, before any unzipping takes place, but you've messed up the 
line numbers (probably by editing the file after importing it).


-- 
Steven

>>
The problem is happening when it is coming to write option.

The * is not the real name of the zip file, I just hide the name.

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


RE: unzip problem

2011-06-24 Thread Ahmed, Shakir


-Original Message-
From: python-list-bounces+shahmed=sfwmd@python.org
[mailto:python-list-bounces+shahmed=sfwmd@python.org] On Behalf Of
Philip Semanchuk
Sent: Friday, June 24, 2011 11:18 AM
To: Lista-Comp-Lang-Python list
Subject: Re: unzip problem


On Jun 24, 2011, at 10:55 AM, Ahmed, Shakir wrote:

> Hi,
> 
> 
> 
> I am getting following error message while unziping a .zip file. Any
> help or idea is highly appreciated.
> 
> 
> 
> Error message>>>
> 
> Traceback (most recent call last):
> 
>  File "C:\Zip_Process\py\test2_new.py", line 15, in 
> 
>outfile.write(z.read(name))
> 
> IOError: (22, 'Invalid argument')


Start debugging with these two steps --
1) Add this just after "for name in z.namelist():"
   print name

That way you can tell which file is failing.

2) You can't tell whether you're getting an error on the write or the
read because you've got two statements combined into one line. Change
this --
   outfile.write(z.read(name))
to this --
   data = z.read(name)
   outfile.write(data)


Good luck
Philip

> 
> 
> 
> 
> 
> The script is here:
> 
> *
> 
> fh = open('T:\\test\\*.zip', 'rb')
> 
> z = zipfile.ZipFile(fh)
> 
> for name in z.namelist():
> 
>outfile = open(name, 'wb')
> 
> 
> 
>outfile.write(z.read(name))
> 
>print z
> 
>print outfile
> 
>outfile.close()
> 
> 
> 
> fh.close()
> 
> 


The problem found in outfile.Write. The error code is here and is
happening when few of the files are already unzipped from the zip file

>>> T:\applications\tst\py\Zip_Process
>>> drg100.aux
>>> 
>>> 
>>> drg100.fgdc.htm
>>> 
>>> 
>>> drg100.htm
>>> 
>>> 
>>> drg100.sdw
>>> 
>>> 
>>> drg100.sid
>>> Unhandled exception while debugging...
Traceback (most recent call last):
  File "C:\Zip_Process\py\test2_new.py", line 16, in 
outfile.write(data)
IOError: (22, 'Invalid argument')
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unzip problem

2011-06-24 Thread Ethan Furman

Ahmed, Shakir wrote:

Hi,

 


I am getting following error message while unziping a .zip file. Any
help or idea is highly appreciated.

 


Error message>>>

Traceback (most recent call last):

  File "C:\Zip_Process\py\test2_new.py", line 15, in 

outfile.write(z.read(name))

IOError: (22, 'Invalid argument')


I just dealt with this problem on my system -- only pops up when writing 
large files (just over 50Mb for me) to a network drive; no problems when 
writing to a local drive.


Here's how I get around it:

CHUNK_SIZE = 10 * 1024 * 1024

fn = open(uncompressed_file, 'wb')
ptr = 0
size = len(data)
while ptr < size:
fn.write(data[ptr:ptr+CHUNK_SIZE])
ptr += CHUNK_SIZE
fn.close()


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


RE: unzip problem

2011-06-24 Thread steve+comp . lang . python
Ahmed, Shakir wrote:

> The problem is happening when it is coming to write option.
> 
> The * is not the real name of the zip file, I just hide the name.

Please don't waste our time by showing us fake code that doesn't do what you
say it does.

You said that "The script is here", but that was not true, was it? What you
showed us was not the script you were running. What other changes,
deliberate or accidental, did you make?

If you are going to edit the script to make it simpler (a good idea!),
please run it first to make sure you still get the same error.



-- 
Steven

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


python overloading

2011-06-24 Thread anand jeyahar
Not sure, this is the right place, redirect me if it's not.

I was curious about the functionoverloading(
http://svn.python.org/view/sandbox/trunk/overload/) and was trying to do a
svn checkout of the branch and failed. Is it restricted access for even
checkout? How do i get read-only access?

==
Anand Jeyahar
http://sites.google.com/a/cbcs.ac.in/students/anand
==
The man who is really serious,
with the urge to find out what truth is,
has no style at all. He lives only in what is.
  ~Bruce Lee

Love is a trade with lousy accounting policies.
 ~Aang Jie
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: those darn exceptions

2011-06-24 Thread Chris Torek
>Chris Torek wrote:
>> I can then check the now-valid
>> pid via os.kill().  However, it turns out that one form of "trash"
>> is a pid that does not fit within sys.maxint.  This was a surprise
>> that turned up only in testing, and even then, only because I
>> happened to try a ridiculously large value as one of my test cases.

In article <96itucfad...@mid.individual.net>
Gregory Ewing   wrote:
>It appears that this situation is not unique to os.kill(),
>for example,
>
> >>> import os
> >>> os.read(, 42)
>Traceback (most recent call last):
>   File "", line 1, in 
>OverflowError: Python int too large to convert to C long
>
>In fact I'd expect it to happen any time you pass a
>very large int to something that's wrapping a C function.
>
>You can't really blame the wrappers for this -- it's not
>reasonable to expect all of them to catch out-of-range ints
>and do whatever the underlying function would have done if
>it were given an invalid argument.
>
>I think the lesson to take from this is that you should
>probably add OverflowError to the list of things to catch
>whenever you're calling a function with input that's not
>fully validated.

Indeed.  (Provided that your call is the point at which the validation
should occur -- otherwise, let the exception flow upwards as usual.)

But again, this is why I would like to have the ability to use some
sort of automated tool, where one can point at any given line of
code and ask: "what exceptions do you, my faithful tool, believe
can be raised as a consequence of this line of code?"

If you point it at the call to main():

if __name__ == '__main__':
main()

then you are likely to get a useless answer ("why, any exception
at all"); but if you point it at a call to os.read(), then you get
one that is useful -- and tells you (or me) about the OverflowError.
If you point it at a call to len(x), then the tool tells you what
it knows about type(x) and x.__len__.  (This last may well be
"nothing": some tools have only limited application.  However, if
the call to len(x) is preceded by an "assert isinstance(x,
(some,fixed,set,of,types)) for instance, or if all calls to the
function that in turn calls len(x) are visible and the type of x
can be proven, the tool might tell you something useful agin.)

It is clear at this point that a simple list (or tuple) of "possible
exceptions" is insufficient -- the tool has to learn, somehow, that
len() raises TypeError itself, but also raises whatever x.__len__
raises (where x is the parameter to len()).  If I ever get around
to attempting this in pylint (in my Copious Spare Time no doubt
:-) ), I will have to start with an external mapping from "built
in function F" to "exceptions that F raises" and figure out an
appropriate format for the table's entries.  That is about half
the point of this discussion (to provoke thought about how one
might express this); the other half is to note that the documentation
could probably be improved (as someone else already noted elsethread).

Note that, if nothing else, the tool -- even in limited form,
without the kind of type inference that pylint attempts -- gives
you the ability to automate part of the documentation process.
-- 
In-Real-Life: Chris Torek, Wind River Systems
Intel require I note that my opinions are not those of WRS or Intel
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W)  +1 801 277 2603
email: gmail (figure it out)  http://web.torek.net/torek/index.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unzip problem

2011-06-24 Thread Ethan Furman

Ahmed, Shakir wrote:


Thanks for your help and really appreciate your time.

I changed the code as you mentioned and here it is:


fn = open('T:\\applications\\tst\\py\\Zip_Process\\Zip\\myzip.zip',
'rb')
z = zipfile.ZipFile(fn)
for name in z.namelist():


  data = z.read(name)


ptr = 0
size = len(name)  # change this back to data
^- No.  You need the size of the data read in from the 
zipfile for that name, not the length of the name.  Sorry for the omission.



print size
print ptr
while ptr < size:

fn.write(name[ptr:ptr+CHUNK_SIZE]) # change name to data

ptr += CHUNK_SIZE

fn.close()


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


Re: how to write to registry without admin rights on win vista/7

2011-06-24 Thread Andrew Berg
On 2011.06.24 03:48 AM, Duncan Booth wrote:
> http://stackoverflow.com/questions/130763/request-uac-elevation-from-within-a-python-script
Heh. On Windows 7, using 'runas' for the operation in os.startfile()
gives me a normal UAC prompt.

Is there any way to ask for elevation from a subprocess.Popen() call?
Launching an application that normally asks for elevation automatically
fails with error 740 - 'The requested operation requires elevation'. The
runas utility needs an explicit username.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NEED HELP-process words in a text file

2011-06-24 Thread Cousin Stanley

Chris Rebert wrote:

> Netiquette comment: Please avoid SHOUTING 
> 

  The brilliant beam of light that first thought  
  capitilized words amounted to shouting
  never programmed cobol, fortran, or pl/1
  in the 1960s or 1970s  :-) 

  How or why this behavior was cultivated
  and continues to spread is mind boggling 
  to me  :-)


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

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


Re: unzip problem

2011-06-24 Thread Ethan Furman

Ahmed, Shakir wrote:

Thanks once again and you are right I am trying to unzip in the network
share drive. here is the script now: If I am doing any wrong. :
## code start here

import zipfile
import os
import time
dir1 = "T:\\applications\\tst\\py\\Zip_Process"
test = '%s/shp'%dir1
os.chdir(test)
cwd = os.getcwd()
print cwd


CHUNK_SIZE = 10 * 1024 * 1024


fn = open('T:\\applications\\tst\\py\\Zip_Process\\Zip\\myzip.zip',
'rb')
z = zipfile.ZipFile(fn)
for name in z.namelist():
ptr = 0
data = z.read(name)
size = len(data)
print size
print ptr
while ptr < size:

fn.write(data[ptr:ptr+CHUNK_SIZE])

ptr += CHUNK_SIZE

fn.close()

#Code done here.
 
But got error as follows:



T:\applications\tst\py\Zip_Process\shp

59160
0
Traceback (most recent call last):
  File
"C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py"
, line 325, in RunScript
exec codeObject in __main__.__dict__
  File "t:\scratch\shahmed\test2_new.py", line 24, in 
fn.write(data[ptr:ptr+CHUNK_SIZE])
IOError: [Errno 9] Bad file descriptor


I didn't notice this in your last post, but you are using fn as both the 
zipfile name and the name of the file you are writing to.  You'll need 
to create the file you want to write before you write to it (plus any 
intermediate directories).



Here's the (slightly stripped) version I actually use:

8<
import os
from zipfile import  ZipFile

def retrieve_files(zipped, destination, files=None):
"retrieves files from "
CHUNK_SIZE = 10 * 1024 * 1024
try:
os.makedirs(destination)
except WindowsError:
pass
target = ZipFile(zipped, 'r')
stored = dict([(k.filename.lower(), k.filename) for k in 
target.infolist()])

if files is None:
files = [member.filename.lower() for member in target.infolist()]
elif isinstance(files, (str, unicode)):
files = [files.lower()]
else:
files = [f.lower() for f in files]
for compressed_file in files:
uncompressed_file = os.path.join(destination, compressed_file)
path, filename = os.path.split(uncompressed_file)
if not os.path.exists(path):
os.makedirs(path)
if filename == '__empty__':
continue
data = target.read(stored[compressed_file])
fn = open(uncompressed_file, 'wb')
ptr = 0
size = len(data)
while ptr < size:
fn.write(data[ptr:ptr+CHUNK_SIZE])
ptr += CHUNK_SIZE
fn.close()
target.close()
8<

I convert all filenames to lower case since MS Windows doesn't care, but 
Python does.


The test for filename == '__empty__': when I create the zipfile, if the 
directory is empty I store a 0-length file named '__empty__' in that 
subdirectory (actually, it only happens in the zipfile) so that I can 
get the directory back later.


Hope this helps.

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


Re: NEED HELP-process words in a text file

2011-06-24 Thread John Gordon
In  Cousin Stanley  
writes:


>   How or why this behavior was cultivated
>   and continues to spread is mind boggling 

The behavior of writing in all caps, or the behavior of equating such
writing with shouting?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Interpreting Left to right?

2011-06-24 Thread Tycho Andersen
On Fri, Jun 24, 2011 at 12:14:27AM -0700, Ethan Furman wrote:
 
> The example given to me when I had this question:
> 
> --> x = x['huh'] = {}
> --> x
> {'huh': {...}}
> 
> 
> As you can see, the creation of the dictionary is evaluated, and
> bound to the name 'x'; then the key 'huh' is set to the same
> dictionary.

Can you please elaborate? I really don't understand how this works at
all. I would have expected a NameError from this (obviously my mental
model is wrong).

This single line is equivalent to:

x = {}
x['huh'] = x

...but I don't understand how python's evaluation semantics get from
the one liner to the two liner/result at all.

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


Re: Interpreting Left to right?

2011-06-24 Thread Ethan Furman

Tycho Andersen wrote:

On Fri, Jun 24, 2011 at 12:14:27AM -0700, Ethan Furman wrote:
 

The example given to me when I had this question:

--> x = x['huh'] = {}
--> x
{'huh': {...}}


As you can see, the creation of the dictionary is evaluated, and
bound to the name 'x'; then the key 'huh' is set to the same
dictionary.


Can you please elaborate? I really don't understand how this works at
all. I would have expected a NameError from this (obviously my mental
model is wrong).

This single line is equivalent to:

x = {}
x['huh'] = x

...but I don't understand how python's evaluation semantics get from
the one liner to the two liner/result at all.

\t


Think of it this way:

x = x['huh'] = {}

obj = {}   # RHS evaluated first (and only once)

x = obj# then first LHS

x['huh'] = obj # then second LHS, etc


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


RE: unzip problem - solved

2011-06-24 Thread Ahmed, Shakir
-Original Message-
From: Ethan Furman [mailto:et...@stoneleaf.us] 
Sent: Friday, June 24, 2011 3:47 PM
To: Ahmed, Shakir
Cc: Python
Subject: Re: unzip problem

Ahmed, Shakir wrote:
> Thanks once again and you are right I am trying to unzip in the
network
> share drive. here is the script now: If I am doing any wrong. :
> ## code start here
> 
> import zipfile
> import os
> import time
> dir1 = "T:\\applications\\tst\\py\\Zip_Process"
> test = '%s/shp'%dir1
> os.chdir(test)
> cwd = os.getcwd()
> print cwd
> 
> 
> CHUNK_SIZE = 10 * 1024 * 1024
> 
> 
> fn = open('T:\\applications\\tst\\py\\Zip_Process\\Zip\\myzip.zip',
> 'rb')
> z = zipfile.ZipFile(fn)
> for name in z.namelist():
> ptr = 0
> data = z.read(name)
> size = len(data)
> print size
> print ptr
> while ptr < size:
> 
> fn.write(data[ptr:ptr+CHUNK_SIZE])
> ptr += CHUNK_SIZE
> 
> fn.close()
> 
> #Code done here.
>  
> But got error as follows:
> 
 T:\applications\tst\py\Zip_Process\shp
> 59160
> 0
> Traceback (most recent call last):
>   File
>
"C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py"
> , line 325, in RunScript
> exec codeObject in __main__.__dict__
>   File "t:\scratch\shahmed\test2_new.py", line 24, in 
> fn.write(data[ptr:ptr+CHUNK_SIZE])
> IOError: [Errno 9] Bad file descriptor

I didn't notice this in your last post, but you are using fn as both the

zipfile name and the name of the file you are writing to.  You'll need 
to create the file you want to write before you write to it (plus any 
intermediate directories).


Here's the (slightly stripped) version I actually use:

8<
import os
from zipfile import  ZipFile

def retrieve_files(zipped, destination, files=None):
 "retrieves files from "
 CHUNK_SIZE = 10 * 1024 * 1024
 try:
 os.makedirs(destination)
 except WindowsError:
 pass
 target = ZipFile(zipped, 'r')
 stored = dict([(k.filename.lower(), k.filename) for k in 
target.infolist()])
 if files is None:
 files = [member.filename.lower() for member in
target.infolist()]
 elif isinstance(files, (str, unicode)):
 files = [files.lower()]
 else:
 files = [f.lower() for f in files]
 for compressed_file in files:
 uncompressed_file = os.path.join(destination, compressed_file)
 path, filename = os.path.split(uncompressed_file)
 if not os.path.exists(path):
 os.makedirs(path)
 if filename == '__empty__':
 continue
 data = target.read(stored[compressed_file])
 fn = open(uncompressed_file, 'wb')
 ptr = 0
 size = len(data)
 while ptr < size:
 fn.write(data[ptr:ptr+CHUNK_SIZE])
 ptr += CHUNK_SIZE
 fn.close()
 target.close()
8<

I convert all filenames to lower case since MS Windows doesn't care, but

Python does.

The test for filename == '__empty__': when I create the zipfile, if the 
directory is empty I store a 0-length file named '__empty__' in that 
subdirectory (actually, it only happens in the zipfile) so that I can 
get the directory back later.

Hope this helps.

~Ethan~

Thanks a lot to Ethan who really helped to find out the clue in the
code.
Here is the final code that worked to unzip a large file in the network
drive.

CHUNK_SIZE = 10 * 1024 * 1024


fh = open('T:\\applications\\tst\\py\\Zip_Process\\Zip\\myzip.zip',
'rb')
z = zipfile.ZipFile(fh)
for name in z.namelist():
fn = open(name, 'wb')
ptr = 0
data = z.read(name)
size = len(name)  
print size
print ptr
while ptr < size:
#fn.write(data)
fn.write(data[ptr:ptr+CHUNK_SIZE])
ptr += CHUNK_SIZE
fn.close()
fh.close()


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


Re: Interpreting Left to right?

2011-06-24 Thread Tycho Andersen
On Fri, Jun 24, 2011 at 01:13:08PM -0700, Ethan Furman wrote:
> Tycho Andersen wrote:
> >On Fri, Jun 24, 2011 at 12:14:27AM -0700, Ethan Furman wrote:
> >>The example given to me when I had this question:
> >>
> >>--> x = x['huh'] = {}
> >>--> x
> >>{'huh': {...}}
> >>
> >>
> >>As you can see, the creation of the dictionary is evaluated, and
> >>bound to the name 'x'; then the key 'huh' is set to the same
> >>dictionary.
> >
> >Can you please elaborate? I really don't understand how this works at
> >all. I would have expected a NameError from this (obviously my mental
> >model is wrong).
> >
> >This single line is equivalent to:
> >
> >x = {}
> >x['huh'] = x
> >
> >...but I don't understand how python's evaluation semantics get from
> >the one liner to the two liner/result at all.
> >
> >\t
> 
> Think of it this way:
> 
> x = x['huh'] = {}
> 
> obj = {}   # RHS evaluated first (and only once)
> 
> x = obj# then first LHS
> 
> x['huh'] = obj # then second LHS, etc

Yes, I understand that, but I guess I don't understand *why* things
are done that way. What is the evaluation order principle at work
here? I would have expected:

tmp = {}
x['huh'] = tmp # NameEror!

That is, the right hand sides of assignments are evaluated before the
left hand sides. That is (somehow?) not the case here.

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


Re: unzip problem - solved

2011-06-24 Thread Ethan Furman

Ahmed, Shakir wrote:

Here is the final code that worked to unzip a large file in the network
drive.

CHUNK_SIZE = 10 * 1024 * 1024


fh = open('T:\\applications\\tst\\py\\Zip_Process\\Zip\\myzip.zip',
'rb')
z = zipfile.ZipFile(fh)
for name in z.namelist():
fn = open(name, 'wb')
ptr = 0
data = z.read(name)
size = len(name)  
print size

print ptr
while ptr < size:
#fn.write(data)
fn.write(data[ptr:ptr+CHUNK_SIZE])
ptr += CHUNK_SIZE
fn.close()
fh.close()


The 'size = len(name)' should be 'size = len(data)'.

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


Significant figures calculation

2011-06-24 Thread Harold
Hi,

I am looking for an easy way to do significant figure calculations in
python (which I want to use with a class that does unit calculations).
Significant figure calculations should have the semantics explained,
e.g., here: 
http://chemistry.about.com/od/mathsciencefundamentals/a/sigfigures.htm

My hope was that the decimal module would provide this functionality,
but:

>>> print Decimal('32.01') + Decimal(5.325) + Decimal('12')
49.335 # instead of 49
>>> print Decimal('25.624') / Decimal('25')
1.02496   # instead of 1.0
>>> print Decimal('1.2') == Decimal('1.23')
False  # actually not sure how the semantics should be

I tried to modify the DecimalContext (e.g. getcontext().prec = 2) but
that did not lead to the correct behavior. Google and this list didn't
yield a good answer yet...  so I'd be happy to get a good
recommendations or pointers.

P.S. I am aware that significant figure calculation is controversial
and makes implicit assumptions on the probability distributions of the
variables. I am simply looking for an implementation of the (well
defined) arithmetics as defined on the cited website.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interpreting Left to right?

2011-06-24 Thread Ned Deily
In article <20110624200618.gk6...@point.cs.wisc.edu>,
 Tycho Andersen  wrote:
> Yes, I understand that, but I guess I don't understand *why* things
> are done that way. What is the evaluation order principle at work
> here? I would have expected:
> 
> tmp = {}
> x['huh'] = tmp # NameEror!
> 
> That is, the right hand sides of assignments are evaluated before the
> left hand sides. That is (somehow?) not the case here.

http://docs.python.org/py3k/reference/simple_stmts.html#assignment-statem
ents

-- 
 Ned Deily,
 n...@acm.org

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


Re: Significant figures calculation

2011-06-24 Thread Steven D'Aprano
On Fri, 24 Jun 2011 13:05:41 -0700, Harold wrote:

> Hi,
> 
> I am looking for an easy way to do significant figure calculations in
> python (which I want to use with a class that does unit calculations).
> Significant figure calculations should have the semantics explained,
> e.g., here:
> http://chemistry.about.com/od/mathsciencefundamentals/a/sigfigures.htm
> 
> My hope was that the decimal module would provide this functionality,
> but:
> 
 print Decimal('32.01') + Decimal(5.325) + Decimal('12')
> 49.335 # instead of 49
 print Decimal('25.624') / Decimal('25')
> 1.02496   # instead of 1.0
 print Decimal('1.2') == Decimal('1.23')
> False  # actually not sure how the semantics should be
> 
> I tried to modify the DecimalContext (e.g. getcontext().prec = 2) but
> that did not lead to the correct behavior.

Really? It works for me.


>>> import decimal
>>> D = decimal.Decimal
>>> decimal.getcontext().prec = 2
>>>
>>> D('32.01') + D('5.325') + D('12')
Decimal('49')
>>>
>>> D('25.624') / D('25')
Decimal('1.0')

The only thing you have to watch out for is this:

>>> D('1.2') == D('1.23')  # no rounding
False
>>> D('1.2') == +D('1.23')  # force rounding
True



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


Re: Significant figures calculation

2011-06-24 Thread Jerry Hill
On Fri, Jun 24, 2011 at 4:46 PM, Steven D'Aprano
 wrote:
> Really? It works for me.
>
 import decimal
 D = decimal.Decimal
 decimal.getcontext().prec = 2

 D('32.01') + D('5.325') + D('12')
> Decimal('49')

I'm curious.  Is there a way to get the number of significant digits
for a particular Decimal instance?  I spent a few minutes browsing
through the docs, and didn't see anything obvious.  I was thinking
about setting the precision dynamically within a function, based on
the significance of the inputs.

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


Re: Mac OS X 10.6.6 and MacPyhton 2.6 idle doesn't work

2011-06-24 Thread Ned Deily
In article 
<09cae8bf-4b1f-40ea-af36-4ba130c41...@m18g2000vbl.googlegroups.com>,
 mando  wrote:

> I took MacPython 2.6 from here:
> 
> http://www.python.org/ftp/python/2.6.6/python-2.6.6-macosx10.3.dmg
> 
> 
> Also I downloaded Tcl/Tk from here 
> http://www.kyngchaos.com/software/frameworks
> to using the gis software Qgis
> 
> May be here the issue?

I can't reproduce the problem and I really don't see how installing that 
Tcl/Tk framework could cause the problem by itself.  The version of Tcl 
and Tk to dynamically load is added to the executable at link time when 
the installer is being built.  It should look something like this:

$ cd /Library/Frameworks/Python.framework/Versions/2.6
$ cd ./lib/python2.6/lib-dynload/
$ otool -L _tkinter.so 
_tkinter.so (architecture ppc):
   /Library/Frameworks/Tcl.framework/Versions/8.4/Tcl (compatibility 
version 8.4.0, current version 8.4.19)
   /Library/Frameworks/Tk.framework/Versions/8.4/Tk (compatibility 
version 8.4.0, current version 8.4.19)
   /usr/lib/libmx.A.dylib (compatibility version 1.0.0, current version 
47.1.0)
   /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current 
version 88.3.10)
_tkinter.so (architecture i386):
   /Library/Frameworks/Tcl.framework/Versions/8.4/Tcl (compatibility 
version 8.4.0, current version 8.4.19)
   /Library/Frameworks/Tk.framework/Versions/8.4/Tk (compatibility 
version 8.4.0, current version 8.4.19)
   /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current 
version 88.3.10)

Note the absolute path to the framework.  If that version of the 
framework does not exist at that location, the dynamic loader falls back 
to the OS X standard location /System/Library/Frameworks ...

If you've only installed that one extra Tcl/Tk version, things should 
look something like this:

$ ls -l /Library/Frameworks/Tcl.framework/Versions/
total 8
drwxr-xr-x  5 root  admin  272 Jul 27  2010 8.5/
lrwxr-xr-x  1 root  admin3 Jun 24 13:31 Current@ -> 8.5
$ ls -l /Library/Frameworks/Tk.framework/Versions/
total 8
drwxr-xr-x  5 root admin  272 Jul 27  2010 8.5/
lrwxr-xr-x  1 sysadminold  wheel3 Jun 24 13:31 Current@ -> 8.5
$  ls -l /System/Library/Frameworks/Tk.framework/Versions/
total 8
drwxr-xr-x  5 root  wheel  340 Mar 17 18:27 8.4/
drwxr-xr-x  5 root  wheel  340 Mar 17 18:27 8.5/
lrwxr-xr-x  1 root  wheel3 Nov  7  2010 Current@ -> 8.5
$ ls -l /System/Library/Frameworks/Tcl.framework/Versions/
total 8
drwxr-xr-x  5 root  wheel  374 Mar 17 18:27 8.4/
drwxr-xr-x  5 root  wheel  374 Mar 17 18:27 8.5/
lrwxr-xr-x  1 root  wheel3 Nov  7  2010 Current@ -> 8.5

If not, something's wrong.  It's especially odd that you would see a 
problem with IDLE.app since it is not influenced by shell initialization 
steps.  Do you have something set in ~/.MacOSX/environment.plist ?  
Also, try launching that idle from a shell:

$ /usr/local/bin/idle2.6

-- 
 Ned Deily,
 n...@acm.org

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


Re: Interpreting Left to right?

2011-06-24 Thread Terry Reedy

On 6/24/2011 4:06 PM, Tycho Andersen wrote:


tmp = {}
x['huh'] = tmp # NameEror!

That is, the right hand sides of assignments are evaluated before the
left hand sides. That is (somehow?) not the case here.


You are parsing "a = b = c" as "a = (b = c)" which works in a language 
in which assignment is an expression, but does not work in Python where 
assignment is a statement. You have to parse it more as "(a = b) = c" 
but that does not work since then the first '=' is not what it seems. It 
is more like "(both a and b) = c". Perhaps best to expand "a = b = c" to 
"a = c; b = c" and see the first as an abbreviation thereof -- just 
delete the 'c;'.


If I have ever used this sort of multiple assignment, it has been for 
simple unambiguous things like "a = b = 0".


--
Terry Jan Reedy

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


Re: Interpreting Left to right?

2011-06-24 Thread Tycho Andersen
On Fri, Jun 24, 2011 at 01:24:24PM -0700, Ned Deily wrote:
> In article <20110624200618.gk6...@point.cs.wisc.edu>,
>  Tycho Andersen  wrote:
> > Yes, I understand that, but I guess I don't understand *why* things
> > are done that way. What is the evaluation order principle at work
> > here? I would have expected:
> > 
> > tmp = {}
> > x['huh'] = tmp # NameEror!
> > 
> > That is, the right hand sides of assignments are evaluated before the
> > left hand sides. That is (somehow?) not the case here.
> 
> http://docs.python.org/py3k/reference/simple_stmts.html#assignment-statements

Perhaps I'm thick, but (the first thing I did was read the docs and) I
still don't get it. From the docs:

"An assignment statement evaluates the expression list (remember that
this can be a single expression or a comma-separated list, the latter
yielding a tuple) and assigns the single resulting object to each of
the target lists, from left to right."

For a single target, it evaluates the RHS and assigns the result to
the LHS. Thus

x = x['foo'] = {}

first evaluates

x['foo'] = {}

which should raise a NameError, since x doesn't exist yet. Where am I
going wrong?

Thanks,

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


Re: Looking PDF module

2011-06-24 Thread Ervin Hegedüs
hello,

On Fri, Jun 24, 2011 at 09:59:17AM -0700, Cameron Laird wrote:
> Hegedüs Ervin, it's quite likely that ReportLab will be a good
> technical fit
> for you.
it's a good news :)

> Are you in a position to pay licensing fees for advanced
> features?

no :(

> Do you have any requirements to *merge* PDF instances?

may be, hope I don't, but currently I don't know,

> How stringent
> are your
> performance requirements?

there isn't stringent...


thanks:


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


Re: Project-wide variable...

2011-06-24 Thread Terry Reedy

On 6/24/2011 7:30 AM, Gnarlodious wrote:

On Jun 24, 12:27 am, Terry Reedy wrote:


1) Can I tell Executable.py to share Data with ModuleTest.py?


After the import is complete, yes.
import ModuleTest
ModuleTest.Data = Data

This works if the use of Data is inside a function that is not called
during import, not if the use of Data is at toplevel or in a class
statement outside a def.


That works! The solution looks like this:

# controlling program:
from Module import Data
import ModuleTest
ModuleTest.Data = Data
ModuleTest.getData()

# module:
def getData():
 print(Data.Plist.Structure)


This is a form of dependency injection, where a caller injects into a 
callee a dependency (callee) of the callee. It can be used even if the 
callee imports a dependency when it is imported. It is useful for 
testing when you want the callee to use a different dependency for 
testing. Simple example:


# MyModule
import socket
def myconnect(*args):
   ... socket.bind()

# Test_MyModule
import mock_socket
import MyModule
MyModule.socket = mock_socket
... test of MyModule, including MyModule.myconnect

Python makes this trivial without requiring that the otherwise constant 
depedency always be injected or passed (in normal production use) as a 
variable.


In your case, you are free to inject different forms of Data if you wish.

--
Terry Jan Reedy

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


Re: Interpreting Left to right?

2011-06-24 Thread Tycho Andersen
On Fri, Jun 24, 2011 at 05:02:00PM -0400, Terry Reedy wrote:
> On 6/24/2011 4:06 PM, Tycho Andersen wrote:
> 
> >tmp = {}
> >x['huh'] = tmp # NameEror!
> >
> >That is, the right hand sides of assignments are evaluated before the
> >left hand sides. That is (somehow?) not the case here.
> 
> You are parsing "a = b = c" as "a = (b = c)" which works in a
> language in which assignment is an expression, but does not work in
> Python where assignment is a statement. You have to parse it more as
> "(a = b) = c" but that does not work since then the first '=' is not
> what it seems. It is more like "(both a and b) = c". Perhaps best to
> expand "a = b = c" to "a = c; b = c" and see the first as an
> abbreviation thereof -- just delete the 'c;'.
> 
> If I have ever used this sort of multiple assignment, it has been
> for simple unambiguous things like "a = b = 0".

Ah, the point about the grammar is what I was missing. Thanks a bunch!

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


Re: python overloading

2011-06-24 Thread Terry Reedy

On 6/24/2011 2:01 PM, anand jeyahar wrote:

Not sure, this is the right place, redirect me if it's not.

I was curious about the
functionoverloading(http://svn.python.org/view/sandbox/trunk/overload/)
and was trying to do a svn checkout of the branch and failed. Is it
restricted access for even checkout? How do i get read-only access?


I believe that exact link is for web viewing.
What was your exact svn or tortoise svn command?

--
Terry Jan Reedy

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


Re: NEED HELP-process words in a text file

2011-06-24 Thread Cousin Stanley

John Gordon wrote:

> In  Cousin Stanley  
> writes:
>
>>   How or why this behavior was cultivated
>>   and continues to spread is mind boggling 
>
> The behavior of writing in all caps, 
> or the behavior of equating such writing with shouting ?

  The latter  

equating writing in all caps with shouting 

  "It wobbles the mind."
 

-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

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


Re: search through this list's email archives

2011-06-24 Thread Gabriel Genellina
En Fri, 24 Jun 2011 11:33:23 -0300, Grant Edwards  
 escribió:



On 2011-06-24, Gabriel Genellina  wrote:

En Thu, 23 Jun 2011 13:11:32 -0300, Cathy James 
escribi?:


I looked through this forum's archives, but I can't find a way to
search for a topic through the archive. Am I missing something?



Gmane provides a search capability also:
http://blog.gmane.org/gmane.comp.python.general


FWIW, I've found the Gmane search feature to be very unreliable.  It
often overlooks a lot of matching articles for no apparent reason.


It seems no single provider is perfect. Google searching capability is  
quite good, but for some reason, many posts are missing, often the initial  
post head of a thread. The "Python-URL" summaries usually include a Google  
Groups url, but sometimes I have to link to Gmane, velocityreviews.com or  
even to the list archives at python.org because of that problem.


--
Gabriel Genellina

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


Re: Interpreting Left to right?

2011-06-24 Thread Ned Deily
In article <20110624210835.gl6...@point.cs.wisc.edu>,
 Tycho Andersen  wrote:

> On Fri, Jun 24, 2011 at 01:24:24PM -0700, Ned Deily wrote:
> > In article <20110624200618.gk6...@point.cs.wisc.edu>,
> >  Tycho Andersen  wrote:
> > > Yes, I understand that, but I guess I don't understand *why* things
> > > are done that way. What is the evaluation order principle at work
> > > here? I would have expected:
> > > 
> > > tmp = {}
> > > x['huh'] = tmp # NameEror!
> > > 
> > > That is, the right hand sides of assignments are evaluated before the
> > > left hand sides. That is (somehow?) not the case here.
> > 
> > http://docs.python.org/py3k/reference/simple_stmts.html#assignment-statement
> > s
> 
> Perhaps I'm thick, but (the first thing I did was read the docs and) I
> still don't get it. From the docs:
> 
> "An assignment statement evaluates the expression list (remember that
> this can be a single expression or a comma-separated list, the latter
> yielding a tuple) and assigns the single resulting object to each of
> the target lists, from left to right."
> 
> For a single target, it evaluates the RHS and assigns the result to
> the LHS. Thus
> 
> x = x['foo'] = {}
> 
> first evaluates
> 
> x['foo'] = {}
> 
> which should raise a NameError, since x doesn't exist yet. Where am I
> going wrong?

"An assignment statement evaluates the expression list (remember that 
this can be a single expression or a comma-separated list, the latter 
yielding a tuple) and assigns the single resulting object to each of the 
target lists, from left to right."

Also, remember that in Python the "=" is not part of an expression.  
It's a token in the assignment statement.

-- 
 Ned Deily,
 n...@acm.org

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


Re: how to write to registry without admin rights on win vista/7

2011-06-24 Thread Andrew Berg
On 2011.06.24 03:48 AM, Duncan Booth wrote:
> http://stackoverflow.com/questions/130763/request-uac-elevation-from-within-a-python-script
Heh. On Windows 7, using 'runas' for the operation in os.startfile()
gives me a normal UAC prompt.

Is there any way to ask for elevation from a subprocess.Popen() call?
Launching an application that normally automatically asks for elevation
fails with error 740 - 'The requested operation requires elevation'.

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


Re: NEED HELP-process words in a text file

2011-06-24 Thread Steven D'Aprano
On Fri, 24 Jun 2011 19:17:29 +, Cousin Stanley wrote:

> Chris Rebert wrote:
> 
>> Netiquette comment: Please avoid SHOUTING 
> 
>   The brilliant beam of light that first thought capitilized words
>   amounted to shouting never programmed cobol, fortran, or pl/1 in the
>   1960s or 1970s  :-)

That's probably because the use of capitalisation for emphasis pre-dates 
the invention of computers by centuries. It is hardly an accident that 
the technical term for uppercase is derived from the same root as 
"majestic" and "major".

The history of so-called "minuscule" and "majuscule" letters is complex, 
and it hasn't been a universal rule that Capital Letters have ALWAYS been 
read as emphatic, but it has been true for hundreds of years (at least 
for languages that have capital letters).

Not the ONLY form of emphasis, of course (underlining, bold face, italics 
and  l e t t e r - s p a c i n g  are only a few of the other 
alternatives available), but in a plain-text medium with little control 
over the display of font, the use of lower and UPPER case letters is one 
of the few alternatives available. (The use of *markup* seems to have 
been a late invention in English, although in other languages it has been 
used much longer.)

If ONE word in uppercase is read in a SLIGHTLY louder voice, then 
naturally it doesn't take much imagination TO READ EVEN QUITE SHORT 
PASSAGES OF UNINTERRUPTED UPPERCASE WORDS AS SHOUTING LOUDLY -- 
regardless of the poor design of programming languages in the 60s and 70s.


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


Re: those darn exceptions

2011-06-24 Thread Ben Finney
Chris Torek  writes:

> But again, this is why I would like to have the ability to use some
> sort of automated tool, where one can point at any given line of
> code and ask: "what exceptions do you, my faithful tool, believe
> can be raised as a consequence of this line of code?"

“Why, any exception at all”.

> If you point it at the call to main():
>
> if __name__ == '__main__':
> main()
>
> then you are likely to get a useless answer ("why, any exception
> at all"); but if you point it at a call to os.read(), then you get
> one that is useful -- and tells you (or me) about the OverflowError.

No. The answer is *still* “why, any exception at all”. The name
‘os.read’ could be re-bound at run-time to any object at all, so a code
checker that you “point at any given line of code” can't know what the
name will be bound to when that line gets executed.

> If you point it at a call to len(x), then the tool tells you what
> it knows about type(x) and x.__len__.

Which information, before the code is executed, isn't determined.

-- 
 \   “The cost of education is trivial compared to the cost of |
  `\ ignorance.” —Thomas Jefferson |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interpreting Left to right?

2011-06-24 Thread Chris Angelico
On Sat, Jun 25, 2011 at 7:02 AM, Terry Reedy  wrote:
> If I have ever used this sort of multiple assignment, it has been for simple
> unambiguous things like "a = b = 0".

For which it's extremely useful. Initialize a whole bunch of variables
to zero... or to a couple of values:

minfoo=minbar=minquux=1000
maxfoo=maxbar=maxquux=0


There are times when I miss the "assignment is an expression" concept,
but I'd say this syntax covers 90% or more of use cases for assignment
expressions.

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


Re: Significant figures calculation

2011-06-24 Thread steve+comp . lang . python
Jerry Hill wrote:

> I'm curious.  Is there a way to get the number of significant digits
> for a particular Decimal instance?  I spent a few minutes browsing
> through the docs, and didn't see anything obvious.  I was thinking
> about setting the precision dynamically within a function, based on
> the significance of the inputs.

Not officially, so far as I know, but if you're willing to risk using a
private implementation detail that is subject to change:

>>> decimal.Decimal('000123.45000')._int
'12345000'

However, sometimes you may need to inspect the exponent as well:

>>> zero = decimal.Decimal('0.')
>>> zero._int
'0'
>>> zero._exp
-8



-- 
Steven

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


Re: Interpreting Left to right?

2011-06-24 Thread Ben Finney
Tycho Andersen  writes:

> On Fri, Jun 24, 2011 at 01:24:24PM -0700, Ned Deily wrote:
> > http://docs.python.org/py3k/reference/simple_stmts.html#assignment-statements
>
> Perhaps I'm thick, but (the first thing I did was read the docs and) I
> still don't get it. From the docs:
>
> "An assignment statement evaluates the expression list (remember that
> this can be a single expression or a comma-separated list, the latter
> yielding a tuple) and assigns the single resulting object to each of
> the target lists, from left to right."

Notice that, in the grammar given there, there is exactly one
“expression list”, following *all* of the ‘=’s. The “target lists” are
each to the left of an ‘=’.

> For a single target, it evaluates the RHS and assigns the result to
> the LHS. Thus
>
> x = x['foo'] = {}
>
> first evaluates
>
> x['foo'] = {}

No, that's not an “expression list” by the grammar given in the docs.

The expression list consists, in your example, of “{}” only. The target
lists are “x”, then “x['foo']”, in that order.

-- 
 \   “If consumers even know there's a DRM, what it is, and how it |
  `\ works, we've already failed.” —Peter Lee, Disney corporation, |
_o__) 2005 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interpreting Left to right?

2011-06-24 Thread Terry Reedy

On 6/24/2011 5:08 PM, Tycho Andersen wrote:


"An assignment statement evaluates the expression list (remember that
this can be a single expression or a comma-separated list, the latter
yielding a tuple) and assigns the single resulting object to each of
the target lists, from left to right."


This is the 'other' type of 'multiple assignment'

a,b,c = 1,2,3

Order matters here too.

a,a[1] = [1,2],3
a
# [1,3]
# but

a[1], a = 3, [1,2]
will either fail or modify what a was previously bound to before 
rebinding a to [1,2].


--
Terry Jan Reedy

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


Installing Python Apps on Mac Lion

2011-06-24 Thread JKPeck
The Lion version of the OS on the Mac comes with Python 2.7 installed, but it 
is in /System/Library/Frameworks/..., and this area is not writable by third 
party apps.

So is there a consensus on what apps that typically install under the Python 
site-packages directory should do in this situation?  Installing Python from 
python.org puts it in the writable area /Library/Frameworks/Python.framework.

So, what should a Python app installer do?

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


Re: Significant figures calculation

2011-06-24 Thread Harold
> > I tried to modify the DecimalContext (e.g. getcontext().prec = 2) but
> > that did not lead to the correct behavior.
>
> Really? It works for me.

You are right, I did something wrong when attempting to set the
precision.
And the trick with rounding the decimal with the unary + is neat.
It's the first time for me to play with decimals, so bare with me if I
miss
the obvious.

However, this approach forces you to know the number of significant
figures
beforehand -- which is precisely what the arithmetics should do for
you.
What would indeed be nice, is Jerry's suggestion to obtain the number
of
significant bits and write a small wrapper around the number protocoll
implementation that accounts significance and have __str__/__repr__
set
the context dynamically.

I haven't seen anything obvious in the docs, though it might be
possible
to use log10 of the length of some normalized string representation.
-- 
http://mail.python.org/mailman/listinfo/python-list


what's the big deal for print()

2011-06-24 Thread pipehappy
Hi,

Why people want print() instead of print str? That's not a big deal
and the old choice is more natural. Anyone has some clue?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NEED HELP-process words in a text file

2011-06-24 Thread Ethan Furman

Steven D'Aprano wrote:

On Fri, 24 Jun 2011 19:17:29 +, Cousin Stanley wrote:


Chris Rebert wrote:


Netiquette comment: Please avoid SHOUTING 

  The brilliant beam of light that first thought capitilized words
  amounted to shouting never programmed cobol, fortran, or pl/1 in the
  1960s or 1970s  :-)


That's probably because the use of capitalisation for emphasis pre-dates 
the invention of computers by centuries. It is hardly an accident that 
the technical term for uppercase is derived from the same root as 
"majestic" and "major".


The history of so-called "minuscule" and "majuscule" letters is complex, 
and it hasn't been a universal rule that Capital Letters have ALWAYS been 
read as emphatic, but it has been true for hundreds of years (at least 
for languages that have capital letters).


Not the ONLY form of emphasis, of course (underlining, bold face, italics 
and  l e t t e r - s p a c i n g  are only a few of the other 
alternatives available), but in a plain-text medium with little control 
over the display of font, the use of lower and UPPER case letters is one 
of the few alternatives available. (The use of *markup* seems to have 
been a late invention in English, although in other languages it has been 
used much longer.)


If ONE word in uppercase is read in a SLIGHTLY louder voice, then 
naturally it doesn't take much imagination TO READ EVEN QUITE SHORT 
PASSAGES OF UNINTERRUPTED UPPERCASE WORDS AS SHOUTING LOUDLY -- 
regardless of the poor design of programming languages in the 60s and 70s.


Well said.  :)

~Ethan~

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


Re: what's the big deal for print()

2011-06-24 Thread John Gordon
In  
pipehappy  writes:

> Why people want print() instead of print str? That's not a big deal
> and the old choice is more natural. Anyone has some clue?

Because the new Python uses print().  print "str" is the old way.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: what's the big deal for print()

2011-06-24 Thread Terry Reedy

On 6/24/2011 10:39 PM, pipehappy wrote:

Hi,

Why people want print() instead of print str? That's not a big deal
and the old choice is more natural. Anyone has some clue?


print as a function instead of a statement is consistent with input as a 
function, can be overridden with custom versions, can be passed to 
functions as an argument, and can have options passed as arguments 
instead of with terrible syntax hacks.


--
Terry Jan Reedy

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


Re: those darn exceptions

2011-06-24 Thread Chris Angelico
On Sat, Jun 25, 2011 at 10:25 AM, Ben Finney  wrote:
> No. The answer is *still* “why, any exception at all”. The name
> ‘os.read’ could be re-bound at run-time to any object at all, so a code
> checker that you “point at any given line of code” can't know what the
> name will be bound to when that line gets executed.

Sure it can. And KeyboardInterrupt could be raised at any time, too.
But this is a TOOL, not a deity. If Function X is known to call
Function Y and built-in method Z, and also raises FooException, then
X's list of "most likely exceptions" would be FooException +
Y.__exceptions__ + Z.__exceptions__. It won't be perfect, but it'd be
something that could go into an autodoc-style facility. Obviously you
can fiddle with things, but in _ordinary usage_ this is what it's
_most likely_ to produce.

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


Re: what's the big deal for print()

2011-06-24 Thread steve+comp . lang . python
John Gordon wrote:

> In 
> pipehappy  writes:
> 
>> Why people want print() instead of print str? That's not a big deal
>> and the old choice is more natural. Anyone has some clue?
> 
> Because the new Python uses print().  print "str" is the old way.


I think you missed the point of the question, which is, *why* does the new
Python (version 3+) use a function print() instead of a statement?

The problems with print as a statement includes:

It requires special treatment in the compiler, instead of just being an
ordinary function like len(), etc.

It's hard to come up with special syntax to add extra functionality to print
statement. Compare the ugly syntax needed to add support for printing to
writable files in Python 2:

print >>fileobj, arg  # what does the mysterious >> syntax mean?

compared to the natural way it works in Python 3:

print(arg, file=fileobj)

Likewise, changing the delimiter between arguments. Python 3 has:

>>> print(1, 2, 3, sep="*")
1*2*3

while Python 2 requires you to generate the string by hand, and then print
it:

>>> print '*'.join('%s' % x for x in (1, 2, 3))
1*2*3


One Frequently Asked Question is "How do I get rid of the newline after
printing?" In Python 2, you leave a comma at the end of the print
statement. What? A comma? How does that make *any* sense at all???
Unfortunately, while that gets rid of the newline, it also leaves spaces
between items:

>>> def example():
... print 1,
... print 2,
... print 3
...
>>> example()
1 2 3

Here's the Python 3 version:

>>> def example():
... print(1, sep='', end='')
... print(2, sep='', end='')
... print(3, sep='')
...
>>> example()
123


To get the same result in Python 2, you have to use sys.stdout.write().


The canonical explanation for why print is now a function is here:

http://www.python.org/dev/peps/pep-3105/




-- 
Steven

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


Re: Installing Python Apps on Mac Lion

2011-06-24 Thread Ned Deily
In article 
<2ffee45b-8987-4fb4-8c8b-c1eed728e...@glegroupsg2000goo.googlegroups.com
>,
 JKPeck  wrote:

> The Lion version of the OS on the Mac comes with Python 2.7 installed, but it 
> is in /System/Library/Frameworks/..., and this area is not writable by third 
> party apps.
> 
> So is there a consensus on what apps that typically install under the Python 
> site-packages directory should do in this situation?  Installing Python from 
> python.org puts it in the writable area /Library/Frameworks/Python.framework.
> 
> So, what should a Python app installer do?

I don't know about Lion but the Apple-supplied Pythons in previous 
versions of OS X (10.6 and 10.5) install site packages by default into 
/Library/Python.  If you use the Distutils defaults with the system 
Pythons in10.7, they will likely do the same.

-- 
 Ned Deily,
 n...@acm.org

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


Re: how to write to registry without admin rights on win vista/7

2011-06-24 Thread Thorsten Kampe
* miamia (Fri, 24 Jun 2011 01:08:55 -0700 (PDT))
> In my program I can set to run after system startup (it writes path to
> Software\Microsoft\Windows\CurrentVersion\Run)

Under HKLM oder HKCU? The path itself is of course irrelevant.

> but when normal user is logged in my application crashes.

Without an exception?

> I must right click on app an choose "Run As Admin" and then everything
> works.
> 
> How can I do it to write to registry without "Run As Admin" ?

Disable UAC.

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


Re: how to write to registry without admin rights on win vista/7

2011-06-24 Thread Thorsten Kampe
* Andrew Berg (Fri, 24 Jun 2011 14:02:54 -0500)
> On 2011.06.24 03:48 AM, Duncan Booth wrote:
> > http://stackoverflow.com/questions/130763/request-uac-elevation-from-within-a-python-script
> Heh. On Windows 7, using 'runas' for the operation in os.startfile()
> gives me a normal UAC prompt.

That is because UAC for non-admin accounts /is/ runas.

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