Survey - how much do you rely on Free/Open Source Software?

2013-06-28 Thread Tony
Hi,

I'm conducting a survey that aims to measure the importance that Open 
Source/Free Software has to people and organizations around the world.
Answering is very quick (mostly one click per answer)
Please answer it by clicking the link below:
https://docs.google.com/forms/d/1bY5KQgsuPeGMwRoTY2DWU6q-210l7RQ1kcVLRUfLlsA/viewform

After answering, you'll be able to see the results of all answers given so far.

Please help us to obtain accurate data by forwarding this survey to many 
different types of people (meaning, beyound the geek circles!)

NOTE: All answers are optional. Answering only one or two questions is 
perfectly ok.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Zope with mySQL

2011-04-30 Thread Tony
Could you provide more details of what you are trying to do and what
help you need?

On 28/04/11 20:19, harryjatt wrote:
> 
> Hi, i am doing web development with Zope. My connected database is mySQL. I
> am new to this combination.I have to upload the files to mySQL with
> programming in zope and then downloading them via zope.Can you help me in
> this regard? I will be very thankfull to you.
> Regards, Harry

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


Re: how to match list members in py3.x

2018-11-25 Thread tony
On 25/11/2018 17:30, Muhammad Rizwan wrote:
> IF YOU CAN'T HELP BETTER IGNORE THE POST AND DON'T TRY TO BE A SMART ASS.
> 
> 
Why would anyone want to help you?

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


Re: ConfigParser: use newline in INI file

2019-03-07 Thread tony
On 07/03/2019 14:16, jim.womeld...@gmail.com wrote:
> On Saturday, October 1, 2016 at 7:41:40 PM UTC-5, Ned Batchelder wrote:
>> On Saturday, October 1, 2016 at 6:25:16 PM UTC-4, Thorsten Kampe wrote:
>>> * Ben Finney (Sun, 02 Oct 2016 07:12:46 +1100)

 Thorsten Kampe  writes:

> ConfigParser escapes `\n` in ini values as `\\n`.
>>>
>>> Indenting solves the problem. I'd rather keep it one line per value 
>>> but it solves the problem.
>>
>> If you want to have \n mean a newline in your config file, you can 
>> do the conversion after you read the value:
>>
>> >>> "a\\nb".decode("string-escape")
>> 'a\nb'
>>
>> --Ned.
> 
> Wow!  Thanks so much Ned.  I've been looking for the solution to this issue 
> for several days and had nearly given up.
> Jim
> 
How does that translate to Python3?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ConfigParser: use newline in INI file

2019-03-07 Thread tony
On 07/03/2019 16:58, jim.womeld...@gmail.com wrote:
> On Thursday, March 7, 2019 at 8:55:31 AM UTC-6, tony wrote:
>> On 07/03/2019 14:16, jim.womeld...@gmail.com wrote:
>>> On Saturday, October 1, 2016 at 7:41:40 PM UTC-5, Ned Batchelder wrote:
>>>> On Saturday, October 1, 2016 at 6:25:16 PM UTC-4, Thorsten Kampe wrote:
>>>>> * Ben Finney (Sun, 02 Oct 2016 07:12:46 +1100)
>>>>>>
>>>>>> Thorsten Kampe  writes:
>>>>>>
>>>>>>> ConfigParser escapes `\n` in ini values as `\\n`.
>>>>>
>>>>> Indenting solves the problem. I'd rather keep it one line per value 
>>>>> but it solves the problem.
>>>>
>>>> If you want to have \n mean a newline in your config file, you can 
>>>> do the conversion after you read the value:
>>>>
>>>> >>> "a\\nb".decode("string-escape")
>>>> 'a\nb'
>>>>
>>>> --Ned.
>>>
>>> Wow!  Thanks so much Ned.  I've been looking for the solution to this issue 
>>> for several days and had nearly given up.
>>> Jim
>>>
>> How does that translate to Python3?
> 
> I have no idea.  I'm on 2.7.3  
> I'd be interested in knowing if someone would try it on 3.
> I do very little Python programming.  I've written a messaging system for 
> Linuxcnc and could not get it to work using bash, so I tried Python and now, 
> thanks to you, I have it working.
> I can provide you with the code if you want to play with it.  When it is run 
> with an integer as a parameter it displays a message from an INI file.
> Jim
> 

Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> "a\\nb".decode("string-escape")
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'str' object has no attribute 'decode'
>>>
-- 
https://mail.python.org/mailman/listinfo/python-list


Unicode string and metakit database

2005-11-03 Thread Tony
I write a database application with Metakit. My script is like the
following:
...
vw = db.getas("t1[no:I,ch:S,code1:S,code2:S]")
...
*vw.append(no=i,ch=x,code1=y[0],code2=y[1])
...
But errors occured on "*" and it displayed "TypeError: not a Python
string".
x, y[0], y[1] are unicode strings. Doesn't Metakit support unicode or
else?

Thanks a lot!

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


Is Python weak on the web side?

2005-11-19 Thread Tony
If I'd like to learn Python for web-development, what are the options 
available?

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


Re: "Collapsing" a list into a list of changes

2005-02-05 Thread Tony

Alan McIntyre wrote:
> Hi all,
>
> I have a list of items that has contiguous repetitions of values, but

> the number and location of the repetitions is not important, so I
just
> need to strip them out.  For example, if my original list is
> [0,0,1,1,1,2,2,3,3,3,2,2,2,4,4,4,5], I want to end up with
[0,1,2,3,2,4,5].
>
> Here is the way I'm doing this now:
>
> def straightforward_collapse(myList):
>  collapsed = [myList[0]]
>  for n in myList[1:]:
>  if n != collapsed[-1]:
>  collapsed.append(n)
>
>  return collapsed
>
> Is there an elegant way to do this, or should I just stick with the
code
> above?
>
> Thanks,
> Alan McIntyre
> http://www.esrgtech.com

Here is a version using dictionary properties, ie no duplication of
keys.

def condense(l):
 d={}
 for item in l:
d[item]=1
 l=d.keys()
 return l

Cheers
Tony

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


Re: "Collapsing" a list into a list of changes

2005-02-05 Thread Tony

Alan McIntyre wrote:
> Tony,
>
> Actually I only want to remove a certain kind of duplication; 

How about this one liner?
def condense(m):
print [m[0]]+[m[k] for k in range(1,len(m)) if
m[k]!=m[k-1]]
b=[1,1,1,2,2,2,1,1,1]
condense(b)
Tony Clarke

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


Re: Heterogeneous lists

2007-08-07 Thread Tony
On Aug 7, 8:53 pm, Jarek Zgoda <[EMAIL PROTECTED]> wrote:
.
>
> I love my lists of classes. I know, I'll go to hell for that.
>
> --
> Jarek Zgodahttp://jpa.berlios.de/

And I love my shelved lists of classes..

Tony

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


Re: How can I programmatically find the name of a method from within that method?

2007-08-08 Thread Tony
On Aug 8, 8:25 am, Peter Otten <[EMAIL PROTECTED]> wrote:
> kj7ny wrote:
> > What is @checkPrivs (see example copied below from other post)?  In
> > fact... how does the thing work at all?
> > @checkPrivs
> > def add(a,b):
> > return a+b
>
> @... is called a decorator and is just a fancy way of writing
>
> def add(a, b):
> return a+b
> add = checkPrivs(add)
>
> Peter

Is this cheating?

class a:


def square(self, x):

print 'executing:', dir(self)[-1]
print x*x
def cube(self, x):
print 'executing:', dir(self)[-2]
print x*x*x

b=a()



b.square(3)
b.cube(3)
Output:

PyMate r6780 running Python 2.3.5 (python)
>>> function self naming2.py

executing: square
9
executing: cube
27

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


Re: How can I programmatically find the name of a method from within that method?

2007-08-08 Thread Tony
On Aug 8, 9:28 pm, Peter Otten <[EMAIL PROTECTED]> wrote:

> No, just wrong.
>
> >> class A:
>
> ... def alpha(self): return dir(self)[-2]
> ... def gamma(self): return dir(self)[-1]
> ...>>> a = A()
> >>> a.alpha(), a.gamma()
> ('alpha', 'gamma')
> >>> a.beta = 42
> >>> a.alpha(), a.gamma()
>
> ('beta', 'gamma')
>
> Peter
Only wrong if the function is only to write its own name. if it does
something else as well, seems to work:

class a:

def square(self, x):
print 'executing:', dir(self)[-1]
print x*x
def cube(self, x):
print 'executing:', dir(self)[-2]
print x*x*x

b=a()

b.cube(4),b.square(2)
b.c =4
b.cube(3), b.cube(2)



executing: cube
64
executing: square
4
executing: cube
27
executing: cube
8

cheers

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


SUCK my HUSBAND'S CUM from my CUNT

2007-08-11 Thread Tony
 

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

SUCK my HUSBAND'S CUM from my CUNT

2007-08-11 Thread Tony
 

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

Script to copy database

2007-08-14 Thread Tony
I'm new at this and would like to know how set up a script to copy a 
database from a local computer to a network at a certain time everyday. 
Should be simple enough, but, as of now I am unfamiliar with how to do this. 
Would this be done by writing a script and setting up a  scheduled task to 
run the script?  Can anyone help me with the script?  Just need it to copy 
an Access database from the local C: drive to a network F: drive.

Thanks,
Tony 


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


Re: Script to copy database

2007-08-14 Thread Tony
Thanks Laurent.  That was very helpful.  Pretty easy too.

Thanks again for your help.
Tony



"Laurent Pointal" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Tony a écrit :
>> I'm new at this and would like to know how set up a script to copy a 
>> database from a local computer to a network at a certain time everyday. 
>> Should be simple enough, but, as of now I am unfamiliar with how to do 
>> this. Would this be done by writing a script and setting up a  scheduled 
>> task to run the script?  Can anyone help me with the script?  Just need 
>> it to copy an Access database from the local C: drive to a network F: 
>> drive.
>>
>> Thanks,
>> Tony
>
> As you wrote about c: and f:, I imagine you are working under Windows.
> IMHO you dont need Python for that.
>
> domybackup.bat
>
> copy c:\mypathtothefile\thefile.xxx F:\mypathdobackudir\
>
>
> And use your "planificateur de taches" (its corresponding english control 
> panel) to setup a periodic call to this batch file, eventually associate 
> an ad-hoc account to the task, so that the batch can access the file to 
> backup.
>
>
> If you need more (ie. network access to setup/clean), here is a copy of a 
> script I use to export (using a Python script) an Access database. Just 
> replace the call to the Python script by a simple call to copy xxx .
>
>
>
> @echo off
> REM LANCEMENT DE L'EXPORT DE LA BASE ADMINISTRATIVE EN MODE TACHE
> REM DE FOND (BATCH).
>
> SET EXPORTS_BATCH=1
> REM Parametres pour se connecter a la machine de transfert.
> SET EXPORTS_HOST=thecomputer
> SET EXPORTS_SHARE=data
> SET EXPORTS_DRIVE=O:
> SET EXPORTS_USER=theremotuser
> SET EXPORTS_PASSWD=theremotepasswd
> REM Montage du volume.
> REM le start pour permettre d'attendre que le montage soit effectif.
> START /wait NET USE %EXPORTS_DRIVE% \\%EXPORTS_HOST%\%EXPORTS_SHARE% 
> %EXPORTS_PASSWD% /USER:%EXPORTS_USER% /PERSISTENT:No
> IF ERRORLEVEL 1 GOTO erreur_montage
>
> REM Parametres pour le script Python.
> SET SCRIPT_EXPORT="C:\Documents and Settings\myaccount\My 
> Documents\mybexport.py"
> SET DSN_BASE_ADMIN=mydbaccound
> SET LOGIN_BASE_ADMIN=mydbpasswd
> SET PATH_FICHIERS_EXPORTS=%EXPORTS_DRIVE%\
> REM Variables d'environnement eventuellement utiles...
> SET TEMP=%PATH_FICHIERS_EXPORTS%
> SET TMP=%PATH_FICHIERS_EXPORTS%
> REM Lancement du script Python qui realise l'export.
> C:\Tools\Python24\python.exe %SCRIPT_EXPORT%
>
> REM Deconnexion du volume.
> NET USE %EXPORTS_DRIVE% /DELETE
>
> goto termine
>
> :erreur_montage
> ECHO "Erreur %ERROR_LEVEL% au montage de \\%EXPORTS_HOST%\%EXPORTS_SHARE% 
> en lecteur %EXPORTS_DRIVE%."
>
> :termine 


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

Re: Latest models of Gibson guitars

2007-08-21 Thread Tony
I don't who is posting here stupid shit about guitars
who ever is do self fever hang your self with one of strings


"kaldrenon" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Aug 20, 8:54 pm, Twisted <[EMAIL PROTECTED]> wrote:
>> If the message then
>> says something absurd, like "this is a newsgroup about Python" when
>> I'm reading it in cljp, well, what do you expect? :P
>
> I think most would expect you to go, "WTF?" but then, like a rational
> person, click the helpful little "More options" link that GG provides
> (I'm assuming you use GG to read as well as to post, forgive me if I'm
> wrong) and double-check before harassing someone because you jumped to
> conclusions.
>
>> though nothing in the headers would indicate this.
>
> Newsgroups: comp.lang.java.programmer,
> microsoft.public.dotnet.framework.aspnet, comp.lang.python,
> rec.photo.digital, alt.home.repair
> From: [EMAIL PROTECTED]
> Date: Sun, 19 Aug 2007 17:34:58 -
> Local: Sun, Aug 19 2007 1:34 pm
> Subject: Latest models of Gibson guitars
>
> That's the header GG shows. Prtty clear.
>
> Just a tip for future reference - all's fair if you weren't aware of
> this feature of GG's interface.
> 


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


Re: Tkinter pack difficulty

2007-09-12 Thread Tony
On Sep 12, 6:22 pm, Simon Forman <[EMAIL PROTECTED]> wrote:
> Hi all,
>
>Snip> Any thoughts or advice?
>
> Thanks in advance,
> ~Simon
>

This seems to do what you want, the difference is that the expand
option is left out top and bottom, also I increased height and put in
a width value as well:
from Tkinter import *

t = Tk()

header = Frame(t, bg="black", height=30, width = 10)
header.pack(fill=X, side=TOP, anchor=N)

body = Frame(t, bg="grey")
body.pack(expand=1, fill=BOTH, anchor=CENTER)

log = Frame(t, bg="white", height=30, width = 10)
log.pack( fill=X, side=BOTTOM, anchor=S)

t.mainloop()

Ciao
Tony

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


Re: while within while

2007-10-27 Thread Tony
On Oct 27, 7:11 pm, Shawn Minisall <[EMAIL PROTECTED]> wrote:
> snip
>
> import random
>
> def main():
>
> #define and initialize variables
> #choice as int
> choice = 0
> #weapon choice as int
> weaponchoice = 0
> #number of wins
> win = 0
> #number of loses
> lose = 0
> #number of ties
> tie = 0
> #number of rounds
> rounds = 0
> #play again loop
> again = "no"
>
snip

In Python, you usually don't need to define your variables in advance.
Choice is determined as a number by your use of input() and the
response of the user, and in other code it could later be changed to
another type. So your initial declaration was unnecessary.'Dynamic
typing' its called, one of the joys of the language compared to  Java,
C etc.. So not doing that would make your code a bit simpler, one less
thing to worry about

Tony

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


Re: while within while

2007-10-28 Thread Tony
 Shawn Minisall wrote:


also, surely it should be paper covers rock?

Tony


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


Europe Tests Established Chemicals on Millions of Animals

2007-02-22 Thread TONY
Tony
Nottingham
England

22 February 2007

TO: All People Who Care

I  am  a  private individual posting  this message  to help
Laboratory Animals and us all.  I apologize if  this seems
out of place in  this group but I  think  you need to know
this.

A   new   European   Chemical   TestingPolicycalled
REACH  has  now   been   finalised   bythe   European
Union.  Under  these  proposals   Chemicalsofevery
kind  - from  those used  in  industrial  processes to  the
ingredients  of  consumer products  - will   be  tested  on
Millions of  animals from  mice to  fish  to  dogs, causing
untold suffering.

Still worse,  because of  this reliance on outdated  animal
techniques, reliable  and  relevant  information will not be
provided and our safety will not be assured.

If  you  believe  that  REACH  should make  more  use  of
Alternative Testing   to   test  1000s  of   Chemicals  that
have  been   in   general   use  since   before  1985  then
please  take  action  now.

If  you are a  European  citizen  please  contact your local
papers  and   own   MEP  asking   them   to  promote   the
development  of  humane   non-animal   testing   methods
under  the  REACH  legislation, which  is  the  best   hope
we  have  for  sparing  animals  the  misery  of  a  testing
laboratory.

A  sample   letter  can  be found at the BUAV (British
Union for the Abolition of Vivisection) website at
www.BUAV.org  (Select Campaigns,  Chemical Testing,
Get Active then Writing to the local press).

For   all  Non-European  members,  you   can  still   help.
Please tell  all  your colleagues and  friends in  the   UK
and   Europe   about  REACH.  Write  to  your  own  local
papers  to  try  and inform others  about  what   is  going
on in Europe.

The website for the European Parliament is
http://www.europarl.europa.eu.
Information  on  REACH,  the  New  European  Chemical
Testing Policy can be found here.

Everyone can help and you can make  a  difference.

Thank You

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


Re: Python beginner!

2007-11-15 Thread Tony
On Nov 15, 8:57 pm, Wildemar Wildenburger
<[EMAIL PROTECTED]> wrote:
>
> Please read this:
> http://www.catb.org/~esr/faqs/smart-questions.html>
>
> Then ask again.
>
> /W

Give me back the old comp.lang.python, where anyone could ask anything
and be sure of a range of replies, instead of this sort of
pedanticism. Sorry, nothing personal, maybe Python users have become
too professional and geeky to remember that Python's main objective is
fun, that is why it is called Python.

Telling the asker to go and learn how to ask properly is not fun, it
reeks of arrogance, high handedness and rejection of newcomers.
Nothing personal Wildemar, I have seen lots of others reply in  a
similar fashion. Am I alone in thinking this group has changed in
these ways?

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


Re: Python beginner!

2007-11-15 Thread Tony
On Nov 15, 8:38 pm, "SMALLp" <[EMAIL PROTECTED]> wrote:
> Could someone please paste some program in wxPython that uses inharitance. I
> would be very thankfull.

HI SMALLp: welcome to Python!

Here is a link that shows some basics of inheritance in Wx, try other
searches on Google:)

http://www.ibiblio.org/obp/py4fun/gui/wxPhone.html

Hope this helps

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


Re: Control mouse position and clicking

2007-11-28 Thread Tony
On Nov 28, 9:33 pm, Bjoern Schliessmann  wrote:
snip
>
> On Mac, IIRC, you can't.
>
> Regards,

well, you can do it from Java, (the Robot class, as I recall), so you
should be able to do it in Jython, which is a Python implementation,
so

Tony

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


Re: Control mouse position and clicking

2007-11-28 Thread Tony
On Nov 28, 9:33 pm, Bjoern Schliessmann  wrote:
snip
>
> On Mac, IIRC, you can't.
>
> Regards,

well, you can do it from Java, (the Robot class, as I recall), so you
should be able to do it in Jython, which is a Python implementation,
so

Tony

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


different errors, return outside function and others

2009-02-22 Thread Tony
Hi,
I am trying to write a small program for my final for school, everytime i
run my program it gives me a return outside function error (after i fixed
all the indentation errors it throws at me), i am not very good at
programing with python atm, so any help would be appreiciated. and if im
missing somethign please feel free to throw
any suggestions out there.

#This is a Text based RPG
# HP = Character hit points, ZHP = Zombie Hit points, ZBHP = Zombie Boss Hit
Points
def fakemain(): #This is a place holder for me untill im ready to run the
program
start()
startselection = start()
if startselection == 1:
character_creation()
else:
#end game (need the code to exit program)

charselection = character_creation()
if charselection == 1:
name = raw_input ('Please Enter Your Name')
HP = dice_roll2()
print 'Your HP is ',HP
elif charselection == 2:
name = raw_input ('Please Enter Your Name')
HP = dice_roll()
print 'Your HP is ',HP
else:

intro_area()
introselection = intro_area()
if introselection == 1:
print 'A Zombie Attacks you'
fight(HP, ZHP, weapon)
death(HP, ZHP, ZBHP)
intro_area()
else:
back_yard()
backyardselection = back_yard()
if backyardselection == 1:
fight(HP, ZHP, weapon)
death(HP, ZHP, ZBHP)
else:
print 'The Zombie leaps and reaches you before you shut the door.'
print 'YOU HAVE DIED!!!'
#reset the game (need the code to reset program)

Alley()
alleyselection = Alley()
if alleyselection == 1:
police_station()
else:   #The object here is for the person to die if they select option
2
print 'As you try to get something to munch on 5 zombies attack you'
fight(HP, ZHP, weapon)
death(HP, ZHP, ZBHP)
fight(HP, ZHP, weapon)
death(HP, ZHP, ZBHP)
fight(HP, ZHP, weapon)
death(HP, ZHP, ZBHP)
fight(HP, ZHP, weapon)
death(HP, ZHP, ZBHP)
fight(HP, ZHP, weapon)
death(HP, ZHP, ZBHP)
policeselection = police_station()
if policeselection == 1:
fight(HP, ZHP, weapon)
death(HP, ZHP, ZBHP)
fight(HP, ZHP, weapon)
death(HP, ZHP, ZBHP)
else:
print 'The door mysteriously locked itself'
police_station()
police_backdoor()
policebackselection = police_backdoor()
if policebackselection == 1:
forest()
else:
print 'The Front Door is locked only way out is the backdoor'
police_backdoor()

forestselection = forest()
if forestselection == 1:
fight(HP, ZBHP, weapon, True)
death(HP, ZHP, ZBHP)
end()
else:
print 'Jonas reaches you before you get back and eats your brains'
#End game
endselection = end()
if endselection == 1:
#End program or play rick roll'd haha
else:
#reset program


#This mod is the first area you are in
def intro_area():
introselection = 0
print ' Welcome to Zombie Survival'
print ' It is a quite night in Egad, Wisconsin when..You suddenly awake'
print ' to the sounds from outside. You see sparks outside from your
window.'
print ' The phone line has been cut. You have nothing to help you fend'
print ' of attackers. What will you do!!!'
print
print '1. Open the Front door?'
print '2. Go out the back door and towards the alley?'
while introselection < 1 or introselection > 2
print 'That area is unavaible please buy the expansion haha'
return introselection

#This is the second area of the RPG
def back_yard():
backyardselection = 0
print ' As you make your way out the back door, a Zombie appears from
the'
print ' side of the yard. He is slowly making his way to you, and you
have'
print ' to kill him to get to the alley. What course of action will you
take.'
print
print '1.Fight the Zombie?'
print '2.Run Away?'
while backyardselection < 1 or backyardselection > 2:
print 'That is a unavailible course of action.'
#fight zombie
return backyardselection

#The Alley No Zombie fight here
def Alley():
alleyselection = 0
print 'After you killed the Zombie you begin to cautiously walk down the
alley'
print 'looking for something to help you fend off anymore Zombies. When
you'
print 'get near the end of the alley you find a baseball bat and a first
aid'
print 'kit laying on the ground, You instinctifly pick up the bat and
first'
print 'aid kit, You reach the end of the alley, and you look around for
a'
print 'place to hide. Then you remeber about the forest beyond the
police'
print 'station. What will you do?'
print
print '1.Run to the police station?'
print '2.Run to the grocery store?'
while alleyselection < 1 or alleyselection > 2:
print 'Theres a group of zombies over there!!'
return alleysele

Re: different errors, return outside function and others

2009-02-23 Thread Tony
The full error message says "There's an error in your program: *** 'return'
outside function (final(2).py, line 114)
 which is were this return statement is..

while introselection < 1 or introselection > 2:
print 'That area is unavaible please buy the expansion haha'
return introselection
On Sun, Feb 22, 2009 at 10:51 PM, Tony  wrote:

> Hi,
> I am trying to write a small program for my final for school, everytime i
> run my program it gives me a return outside function error (after i fixed
> all the indentation errors it throws at me), i am not very good at
> programing with python atm, so any help would be appreiciated. and if im
> missing somethign please feel free to throw
> any suggestions out there.
>
> #This is a Text based RPG
> # HP = Character hit points, ZHP = Zombie Hit points, ZBHP = Zombie Boss
> Hit Points
> def fakemain(): #This is a place holder for me untill im ready to run the
> program
> start()
> startselection = start()
> if startselection == 1:
> character_creation()
> else:
> #end game (need the code to exit program)
>
> charselection = character_creation()
> if charselection == 1:
> name = raw_input ('Please Enter Your Name')
> HP = dice_roll2()
> print 'Your HP is ',HP
> elif charselection == 2:
> name = raw_input ('Please Enter Your Name')
> HP = dice_roll()
> print 'Your HP is ',HP
> else:
>
> intro_area()
> introselection = intro_area()
> if introselection == 1:
> print 'A Zombie Attacks you'
> fight(HP, ZHP, weapon)
> death(HP, ZHP, ZBHP)
> intro_area()
> else:
> back_yard()
> backyardselection = back_yard()
> if backyardselection == 1:
> fight(HP, ZHP, weapon)
> death(HP, ZHP, ZBHP)
> else:
> print 'The Zombie leaps and reaches you before you shut the door.'
> print 'YOU HAVE DIED!!!'
> #reset the game (need the code to reset program)
>
> Alley()
> alleyselection = Alley()
> if alleyselection == 1:
> police_station()
> else:   #The object here is for the person to die if they select option
> 2
> print 'As you try to get something to munch on 5 zombies attack
> you'
> fight(HP, ZHP, weapon)
> death(HP, ZHP, ZBHP)
> fight(HP, ZHP, weapon)
> death(HP, ZHP, ZBHP)
> fight(HP, ZHP, weapon)
> death(HP, ZHP, ZBHP)
> fight(HP, ZHP, weapon)
> death(HP, ZHP, ZBHP)
> fight(HP, ZHP, weapon)
> death(HP, ZHP, ZBHP)
> policeselection = police_station()
> if policeselection == 1:
> fight(HP, ZHP, weapon)
> death(HP, ZHP, ZBHP)
> fight(HP, ZHP, weapon)
> death(HP, ZHP, ZBHP)
> else:
> print 'The door mysteriously locked itself'
> police_station()
> police_backdoor()
> policebackselection = police_backdoor()
> if policebackselection == 1:
> forest()
> else:
> print 'The Front Door is locked only way out is the backdoor'
> police_backdoor()
>
> forestselection = forest()
> if forestselection == 1:
> fight(HP, ZBHP, weapon, True)
> death(HP, ZHP, ZBHP)
> end()
> else:
> print 'Jonas reaches you before you get back and eats your brains'
> #End game
> endselection = end()
> if endselection == 1:
> #End program or play rick roll'd haha
> else:
> #reset program
>
>
> #This mod is the first area you are in
> def intro_area():
> introselection = 0
> print ' Welcome to Zombie Survival'
> print ' It is a quite night in Egad, Wisconsin when..You suddenly
> awake'
> print ' to the sounds from outside. You see sparks outside from your
> window.'
> print ' The phone line has been cut. You have nothing to help you fend'
> print ' of attackers. What will you do!!!'
> print
> print '1. Open the Front door?'
> print '2. Go out the back door and towards the alley?'
> while introselection < 1 or introselection > 2
> print 'That area is unavaible please buy the expansion haha'
> return introselection
>
> #This is the second area of the RPG
> def back_yard():
> backyardselection = 0
> print ' As you make your way out the back door, a Zombie appears from
> the'
>

Re: different errors, return outside function and others

2009-02-23 Thread Tony
ok thank you for that input, this is my first class in programming and its
the only one the school offers. im pretty sure those are supposed to be
modules
that im writting. would it make a difference if those were modules and not
functions? kinda stupid question there but im trying to learn as much as
possible.
Also anything with def infront of it example def start(): would be a
function correct? also im Using 2.5 and the IDLE to do this

On Mon, Feb 23, 2009 at 12:23 AM, Gabriel Genellina
wrote:

> En Mon, 23 Feb 2009 04:51:39 -0200, Tony 
> escribió:
>
> Hi,
>> I am trying to write a small program for my final for school, everytime i
>> run my program it gives me a return outside function error (after i fixed
>> all the indentation errors it throws at me), i am not very good at
>> programing with python atm, so any help would be appreiciated. and if im
>> missing somethign please feel free to throw
>> any suggestions out there.
>>
>
> Is this your *actual* code? It does not even compile...
> Things like 'def foo(...):' are *functions*, not *modules*.
>
> Variables inside functions (including its arguments) are locals, private to
> the function. Even if you modify them, the "outside world" doesn't notice.
> So a function like this:
>
> def fight(HP, ZHP, weapon, boss=False):
>>if weapon == 'fist':
>>while HP > 0 and ZHP > 0:
>>damage = 2
>>ZHP = ZHP - damage
>>if boss:
>>HP = HP - dice_roll2()
>>else:
>>HP = HP - 2
>>elif weapon == 'baseball bat':
>>
>  [... more code ...]
>
> won't alter the "global" values HP, ZHP; in fact, it won't do nothing.
>
> Either return the new values:
>   return HP, ZHP
> and also adjust everywhere you call:
>   HP, ZHP = fight(HP, ZHP, ...)
>
> Or mark HP, ZHP as globals (using the global statement).
>
> --
> Gabriel Genellina
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: different errors, return outside function and others

2009-02-23 Thread Tony
Thank You, I now understand what i need to do now, and again Thanks

On Mon, Feb 23, 2009 at 1:57 AM, Gabriel Genellina
wrote:

> En Mon, 23 Feb 2009 07:07:57 -0200, Tony 
> escribió:
>
> ok thank you for that input, this is my first class in programming and its
>> the only one the school offers. im pretty sure those are supposed to be
>> modules
>> that im writting. would it make a difference if those were modules and not
>> functions? kinda stupid question there but im trying to learn as much as
>> possible.
>>
>
> Each module is a separate file, with extension .py
> If you put all your code in a single file, you write a single module.
> That's fine in this case, unless it grows to something unmanageable.
>
> Functions are blocks of code that have a name and "do" something specific,
> and usually return some result. They start with the keyword "def". You have
> defined several functions already, but called them "modules" in the
> comments, that's wrong and may be confusing.
>
> Also anything with def infront of it example def start(): would be a
>> function correct? also im Using 2.5 and the IDLE to do this
>>
>
> Exactly!
>
> I think you have written so much code without testing it. It's time to test
> every piece now. Start with... the start function, obviously!
>
> But before, you have to clean your code. There are a few strange lines that
> should not be there (all those lines on the left margin that aren't "def"
> statements, like intro_area(), alley()...). Just remove or comment them.
>
> Then you can start testing each function, one at a time. Simply call the
> function with the desired parameters (if any), right at the bottom of the
> file. To test the first one (start), use something like this:
>
> print "about to call start()"
> result = start()
> print "start() finished, result=", result
>
> and do the same for each individual function. Once you know each piece
> works fine, you can start combining them until you build the complete
> program.
>
>
> --
> Gabriel Genellina
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


accessing gmail

2009-12-17 Thread Tony
I'm having trouble getting to gmail messages.  I can access my googlemail 
account through imap with no problems, that's an old one.  The problem is 
trying to get to my current gmail account, which is actually 
t...@tonyburrows.com.  The page shows up as 
mail.google.com/a/tonyburrows.com and I can't see how to get at it.

mail = imaplib.IMAP4_SSL('imap.gmail.com, 993)
mail.login(username, password)

logs me in to my googlemail account and lets me collect mail in that one, 
but how do I get to the gmail one?

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


Re: accessing gmail

2009-12-17 Thread Tony
Intchanter / Daniel Fackrell wrote:

> http://mail.google.com/support/bin/answer.py?hl=en&answer=77654

Thanks!

Actually I had a sudden inspiration last night as I went to bed.  I'd set 
up Thunderbird, all I needed to do was use the same full h...@domain as the 
username.  Stupid, stupid - I'd wasted so much time and it was so simple.  
I will remember it though.

Now to figure out the rest of it.

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


Boolean value of generators

2010-10-14 Thread Tony
I have been using generators for the first time and wanted to check for
an empty result.  Naively I assumed that generators would give
appopriate boolean values.  For example

def xx():
  l = []
  for x in l:
yield x

y = xx()
bool(y)


I expected the last line to return False but it actually returns True.
Is there anyway I can enhance my generator or iterator to have the
desired effect?

Regards

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


python/c api

2010-10-14 Thread Tony
hi,

is the python/c api extensively used? and what world-famous software
use it? thanks!

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


cunfused why gevent block redis' socket request?

2012-12-28 Thread Tony Shao
GOAL:spawn a few greenlet worker deal with the data pop from redis (pop from 
redis and then put into queue)

RUNNING ENV: ubuntu 12.04
PYTHON VER: 2.7
GEVENT VER: 1.0 RC2
REDIS VER:2.6.5
REDIS-PY VER:2.7.1

from gevent import monkey; monkey.patch_all()
import gevent
from gevent.pool import Group
from gevent.queue import JoinableQueue
import redis

tasks = JoinableQueue()
task_group = Group()

def crawler():
while True:
if not tasks.empty():
print tasks.get()
gevent.sleep()

task_group.spawn(crawler)
redis_client = redis.Redis()
data = redis_client.lpop('test') #<--Block here
tasks.put(data)


Try to pop data from redis, but it blocked..and no exception raised...just 
freeze
and remove spawn method ,it will worked..
i feel confuse what happened, plz help!
thk u!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python reading file memory cost

2011-08-01 Thread Tony Zhang
Thanks!

Actually, I used .readline() to parse file line by line, because I need
to find out the start position to extract data into list, and the end
point to pause extracting, then repeat until the end of file.
My file to read is formatted like this:

blabla...useless
useless...

/sign/
data block(e.g. 10 cols x 1000 rows)
...
blank line
/sign/
data block(e.g. 10 cols x 1000 rows)
...
blank line
...
...
EOF
let's call this file 'myfile'
and my python snippet:

f=open('myfile','r')
blocknum=0 #number the data block
data=[]
while True"
# find the extract begnning
while not f.readline().startswith('/a1/'):pass
# creat multidimensional list to store data block   
data=append([])
blocknum +=1
line=f.readline()

while line.strip():  
# check if the line is a blank line, i.e the end of one block
data[blocknum-1].append(["2.6E" %float(x) for x in 
line.split()])
line = f.readline()
print "Read Block %d" %blocknum
if not f.readline(): break 

The running result was that read a 500M file consume almost 2GB RAM, I
cannot figure it out, somebody help!
Thanks very much!

--Tony

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


--------------> Web design in Chennai <--------------

2011-03-03 Thread tony player
Web Design in Chennai

**
   http://webdesignchennai.co.in/

**


Web Design Chennai offers Web Design in Chennai,website
designing,maintenance in chennai,Web Designing and development
Companies Chennai,web hosting in chennai,web site maintenance chennai.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Single line if statement with a continue

2022-12-18 Thread Tony Oliver
On Saturday, 17 December 2022 at 23:58:11 UTC, avi.e...@gmail.com wrote:
> Is something sort of taboo when using something like a computer language to 
> write a program?

With what else would you write a program?
-- 
https://mail.python.org/mailman/listinfo/python-list


PSYCOPG2

2021-02-12 Thread Tony Ogilvie
I am trying to write a program to open a PostgesSQL 13 database using
psycopg2. All seems to work if I write direct to Python but if I write the
script into IDLE it does not work with the IDLE Shell 3.9.1 reporting an
error of no attribute 'connect'.

 

I have tried many options to try and get this to work.

 

Regards

 

Tony

 

 



 

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


RE: PSYCOPG2

2021-02-13 Thread Tony Ogilvie
Thank you

I have tried Sublime 3 and the same thing happens. I do not think I have
another version of Python on my PC. I am trying to look through my files to
find out.

Regards

Tony


-Original Message-
From: Mladen Gogala  
Sent: 13 February 2021 05:35
To: python-list@python.org
Subject: Re: PSYCOPG2

On Fri, 12 Feb 2021 18:29:48 +, Tony Ogilvie wrote:

> I am trying to write a program to open a PostgesSQL 13 database using 
> psycopg2. All seems to work if I write direct to Python but if I write 
> the script into IDLE it does not work with the IDLE Shell 3.9.1 
> reporting an error of no attribute 'connect'.
> 
> 
>  
> I have tried many options to try and get this to work.
> 
> 
>  
> Regards
> 
> 
>  
> Tony

It looks like your idle is not using the same interpreter that you are using
when writing direct code. Anyway, my advice would be to ditch Idle and use
VSCode. It's fabulous.



--
Mladen Gogala
Database Consultant
https://dbwhisperer.wordpress.com


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


tkinter

2021-08-21 Thread Tony Genter
   Tkinter stopped working overnight from 8/20/2021 to 8/21/2021.  Last night
   I was working on tutorials to work on a GUI and this morning every file
   that uses tkinter is broken stating that no module `tkinter' exists.



   Please let me know if there is some sort of problem.  I am removing visual
   studios, all versions of python, sublime text, atom, etc and reinstalling
   all of it to try and resolve the issue.





   Thanks,



   Talat



   Sent from [1]Mail for Windows





References

   Visible links
   1. https://go.microsoft.com/fwlink/?LinkId=550986
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Understanding the working mechanis of python unary arithmetic operators.

2021-10-02 Thread Tony Oliver
On Saturday, 2 October 2021 at 13:48:39 UTC+1, hongy...@gmail.com wrote:
> On Saturday, October 2, 2021 at 4:59:54 PM UTC+8, ju...@diegidio.name wrote: 
> > On Saturday, 2 October 2021 at 10:34:27 UTC+2, hongy...@gmail.com wrote: 
> > > See the following testings: 
> > > 
> > > In [24]: a=3.1415926535897932384626433832795028841971 
> > > In [27]: -a 
> > > Out[27]: -3.141592653589793 
> > You've never heard of floating-point? Double precision has 53 significant 
> > bits of mantissa, corresponding approximately to 16 decimal digits. 
> > 
> >  
> > > In [17]: ~-+1 
> > > Out[17]: 0 
> > << The unary ~ (invert) operator yields the bitwise inversion of its 
> > integer argument. The bitwise inversion of x is defined as -(x+1). It only 
> > applies to integral numbers or to custom objects that override the 
> > __invert__() special method. >> 
> > 
> >  
> > > I'm very puzzled by these operators. Any hints will be highly 
> > > appreciated. 
> > Try and read the proverbial manual: that's truly a fundamental skill...
> Thank you for your explanation. Then what about the following questions?: 
> 
> 1. Should `+' and `-' be classified as binary operators or unary operators?

Both.  See sections 6.6 and 6.7 of the documentation at
https://docs.python.org/3/reference/expressions.html

> As we all know, `a + b', and `a - b' are the normal ways we do basic 
> arithmetic operations. 

Really?  Don't you ever write something like "x = -y"?
Or do you habitually write "x = 0 - y" or "x = 0.0 - y"?

> 2. See the following testings: 
> 
> In [20]: bool(int(True)) 
int(True) -> 1
bool(1) -> True
> Out[20]: True 
> 
> In [21]: bool(~int(True)) 
int(True) -> 1
~1 -> -2
bool(-2) -> True
> Out[21]: True 
> 
> In [22]: bool(~~int(True)) 
int(True) -> 1
~1 -> -2  # these two operations
~(-2) -> 1# cancel each other out
bool(1) -> True
> Out[22]: True 
> 
> In [23]: bool(~~~int(True)) 
Because two consecutive bit-inversions cancel each other out;
this is just a complicated re-statement of operation [21], above
> Out[23]: True 
> 
> In [24]: bool(int(False)) 
int(False) -> 0
bool(0) -> False
> Out[24]: False 
> 
> In [25]: bool(~int(False)) 
int(False) -> 0
~0 -> -1
bool(-1) -> True
> Out[25]: True 
> 
> In [26]: bool(~~int(False)) 
Again, two consecutive inversions cancel each other out
so this is just an over-complicated re-statement of [24]
> Out[26]: False 
> 
> In [27]: bool(~~~int(False)) 
Likewise, this is the equivalent of re-stating [25]
> Out[27]: True 
> 
> Why can’t/shouldn't we get something similar results for both `True' and 
> `False' in the above testings? 

Sorry, I can't parse that.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Selenium py3.8+ DepreciationWarnings - where to find doc to update code?

2021-10-13 Thread Tony Oliver


On Wednesday, 13 October 2021 at 16:16:46 UTC+1, jkk wrote:
> Selenium 3.141+ 
> python 3.8+ 
> ubuntu 20.04 or windows 10 
> 
> I'm trying to upgrade code from py3.6+ to py3.8+ and I'm getting several 
> DepreciationWarnings. 
> 
> Can someone point me to where I can find the documentation that explains how 
> to to remedy these warnings. What are the new preferred coding practices? 
> 
> For example, here is a "DepreciationWarning" that I figured out: 
> 
> py3.6+ 
> from selenium import webdriver 
> browser = browser = webdriver.Firefox() 
> browser.get(url) 
> tables = browser.find_elements_by_tag_name("table") 
> 
> 
> py3.8+ 
> from selenium import webdriver 
> from selenium.webdriver.common.by import By 
> browser = browser = webdriver.Firefox() 
> browser.get(url) 
> tables = browser.find_elements(By.TAG_NAME, "table") 
> or 
> tables = browser.find_elements(By.XPATH, "//table")

I cannot help you with your immediate problem but am intrigued to discover what 
your “browser = browser = “ idiom does that differs from “browser = 
“.
-- 
https://mail.python.org/mailman/listinfo/python-list


any one used moviepy please come in!!! I need help, thanks!

2017-01-24 Thread Tony Chen
I have to use moviepy in one of my project. So I downloaded it, and tried the 
example code on the website. It gives me this error. Anyone can give me some 
help? Thank you very much!

it gives this error:
[MoviePy] This command returned an error !Traceback (most recent call last):
  File "tst.py", line 5, in 
txt_clip = TextClip("My Holidays 2013", fontsize = 70, color = 'white')
  File "/usr/local/lib/python2.7/dist-packages/moviepy/video/VideoClip.py", 
line 1145, in __init__
raise IOError(error)
IOError: MoviePy Error: creation of None failed because of the following error:

convert: not authorized `@/tmp/tmpjistPm.txt' @ 
error/property.c/InterpretImageProperties/3405.
convert: no images defined `PNG32:/tmp/tmpJM0NVq.png' @ 
error/convert.c/ConvertImageCommand/3210.
.

.This error can be due to the fact that ImageMagick is not installed on your 
computer, or (for Windows users) that you didn't specify the path to the 
ImageMagick binary in file conf.py, or.that the path you specified is incorrect
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: any one used moviepy please come in!!! I need help, thanks!

2017-01-25 Thread Tony Chen
On Wednesday, January 25, 2017 at 8:34:01 PM UTC+13, Chris Angelico wrote:
> On Wed, Jan 25, 2017 at 6:22 PM, Tony Chen  wrote:
> > This error can be due to the fact that ImageMagick is not installed on your 
> > computer, or (for Windows users) that you didn't specify the path to the 
> > ImageMagick binary in file conf.py, or.that the path you specified is 
> > incorrect
> 
> So... is ImageMagick installed?
> 
> ChrisA

Okay... Yes it's installed. This problem has been solved haha. Thank you for 
replying.
-- 
https://mail.python.org/mailman/listinfo/python-list


FW: Pycharm Won't Do Long Underscore

2020-06-23 Thread Tony Kaloki



Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10

From: Tony Kaloki<mailto:tkal...@live.co.uk>
Sent: 23 June 2020 19:45
To: python-list@python.org<mailto:python-list@python.org>
Subject: Pycharm Won't Do Long Underscore


Hi Guys,
   I’ve just begun to learn basic computer programming by 
downloading Python and Pycharm and following Youtube tutorials. But I’ve come 
across a problem that’s stopped me in my tracks.
 When I try to do a long underscore __  for classes in Pycharm, it only 
gives me two separate single underscores _ _. This is only in Pycharm, no 
problems anywhere else. Could you tell me how to fix this, because I can’t find 
any answers on the web and I’m not sure if I can go any further in my learning 
without being able to get long underscores.
Sorry if I’m just being really dense, but like I said I’m an absolute 
beginner. Thanks for your time,
Tony
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10


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


Re: Pycharm Won't Do Long Underscore

2020-06-23 Thread Tony Kaloki
Alexander,
   Thank you so much! It worked! Thank you. One question: in 
your reply, are you saying that Python would have treated the two separate 
underscores the same way as a long  underscore i.e. it's a stylistic choice 
rather than a functional necessity?
   In any case, thanks again for your quick and easy to follow - even for me - 
reply.
Tony

Get Outlook for Android<https://aka.ms/ghei36>


From: Alexander Neilson 
Sent: Tuesday, June 23, 2020 9:28:37 PM
To: Tony Kaloki 
Cc: python-list@python.org 
Subject: Re: Pycharm Won't Do Long Underscore

Hi Tony

The “long underscore” (often called Dunder as “double underscore”) is actually 
two underscores as you are seeing shown in PyCharm.

However the display of it as one long underscore is a ligature (special font 
display to communicate clearer) and to enable these in PyCharm go to the 
settings dialog (depending on windows or Mac this could be in different 
locations) and select Editor > Font

In that screen select “enable font ligatures” and if your font supports it 
(like the default JetBrains Mono does) that will start to display the double 
underscores as a single long underscore.

Regards
Alexander

Alexander Neilson
Neilson Productions Limited
021 329 681
alexan...@neilson.net.nz

> On 24/06/2020, at 07:57, Tony Kaloki  wrote:
>
> 
>
> Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
>
> From: Tony Kaloki<mailto:tkal...@live.co.uk>
> Sent: 23 June 2020 19:45
> To: python-list@python.org<mailto:python-list@python.org>
> Subject: Pycharm Won't Do Long Underscore
>
>
> Hi Guys,
>   I’ve just begun to learn basic computer programming by 
> downloading Python and Pycharm and following Youtube tutorials. But I’ve come 
> across a problem that’s stopped me in my tracks.
> When I try to do a long underscore __  for classes in Pycharm, it only 
> gives me two separate single underscores _ _. This is only in Pycharm, no 
> problems anywhere else. Could you tell me how to fix this, because I can’t 
> find any answers on the web and I’m not sure if I can go any further in my 
> learning without being able to get long underscores.
>    Sorry if I’m just being really dense, but like I said I’m an absolute 
> beginner. Thanks for your time,
> Tony
> Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pycharm Won't Do Long Underscore

2020-06-24 Thread Tony Kaloki
Thanks for all your explanations, everyone. Hopefully, I'll know better next 
time I come across a similar case. Now, to try and understand the rest of 
Python...

Get Outlook for Android<https://aka.ms/ghei36>


From: Python-list  on behalf 
of MRAB 
Sent: Wednesday, June 24, 2020 7:28:52 PM
To: python-list@python.org 
Subject: Re: Pycharm Won't Do Long Underscore

On 2020-06-24 18:59, Chris Angelico wrote:
> On Thu, Jun 25, 2020 at 3:51 AM Dennis Lee Bieber  
> wrote:
>>
>> On Tue, 23 Jun 2020 20:49:36 +, Tony Kaloki 
>> declaimed the following:
>>
>> >Alexander,
>> >   Thank you so much! It worked! Thank you. One question: 
>> > in your reply, are you saying that Python would have treated the two 
>> > separate underscores the same way as a long  underscore i.e. it's a 
>> > stylistic choice rather than a functional necessity?
>>
>> There is no "long underscore" in the character set. If there were,
>> Python would not know what to do with it as it was created back when ASCII
>> and ISO-Latin-1 were the common character sets. (Interesting: Windows
>> Character Map utility calls the underscore character "low line").
>
> That's what Unicode calls it - charmap is probably using that name.
>
>> Many word processors are configured to change sequences of hyphens:
>> - -- --- into - – — (hyphen, en-dash, em-dash)... But in this case, those
>> are each single characters in the character map (using Windows-Western,
>> similar to ISO-Latin-1): hyphen is x2D, en-dash is x96, em-dash is x97
>> (note that en-/em-dash are >127, hence would not be in pure ASCII)
>
> Hyphen is U+002D, en dash is U+2013, em dash is 2014. :)
>
Not quite. :-)

Hyphen is U+2010.

U+002D is hyphen-minus; it's does double-duty, for historical reasons.
--
https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Finding where to store application data portably

2005-09-22 Thread Tony Houghton
In <[EMAIL PROTECTED]>,
Ron Adam <[EMAIL PROTECTED]> wrote:

> Tony Houghton wrote:
>
>>  > This works on Win XP.  Not sure if it will work on Linux.
>>  >
>>  > import os
>>  >
>>  > parent = os.path.split(os.path.abspath(os.sys.argv[0]))[0]
>>  > file = parent + os.sep + '.bombz'
>> 
>> Ooh, no, I don't want saved data to go in the installation directory. In
>> general that practice encourages people to run with Admin access, and
>> it's about time Windows users were discouraged from that.
>
> Yes, it occurred to me you didn't want to do that after I posted.
>
> Looks like maybe the correct place would be as you suggested, but maybe 
> doing it this way would be better.
>
> import os
> user = os.path.join( os.environ["USERPROFILE"],
>   'Application Data',
>   'Bombz' )

I like that, it's nice and simple. It doesn't look like it's supported
on Win 9x though, but on 9x using the installation directory would be
acceptable.

-- 
The address in the Reply-To is genuine and should not be edited.
See <http://www.realh.co.uk/contact.html> for more reliable contact addresses.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 350: Codetags

2005-09-26 Thread Tony Meyer
On 27/09/2005, at 12:21 PM, Paul Rubin wrote:

> Neil Hodgson <[EMAIL PROTECTED]> writes:
>
>> The PEP system allows for the documentation of a convention as an
>> "Informational PEP". Documenting conventions is useful.
>
> If the preferred method of doing something is
> consistent enough that it can be codified as a convention in a PEP, it
> should be implemented in the compiler, so it becomes a language
> feature, not a convention.

Does this mean that you think that PEP 8 (Python Code Style Guide)  
should be enforced by the compiler?  So that (e.g) lines that are too  
long just don't compile?

I really doubt you'll find much agreement for this (the compiler  
should enforce it) position.  The 'fewer conventions are better'  
position might enjoy more support, but doesn't strike me as  
particularly Pythonic (e.g. compare whitespace in Python and C).

=Tony.Meyer

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


Re: Will python never intend to support private, protected and public?

2005-09-28 Thread Tony Meyer
On 28/09/2005, at 11:05 PM, Simon Brunning wrote:

> On 9/28/05, could ildg <[EMAIL PROTECTED]> wrote:
>
>> Python is wonderful except that it has no real private and protected
>> properties and methods.
>> Every py object has dict so that you can easily find what fields  
>> and methods
>> an obj has, this is very convenient, but because of this, py is  
>> very hard
>> to support real private and protected?
>
> My convention, attributes with names prefixed with a single underscore
> are private. There's nothing to stop anyone using these, but, well, if
> you take the back off the radio, the warranty is void.

I'm not sure why I haven't seen this mentioned yet, but a leading  
double-underscore does really make a member private:

 >>> class f(object):
...   def __init__(self):
... self.__f = 1
...
 >>> a = f()
 >>> a.__f
Traceback (most recent call last):
   File "", line 1, in ?
AttributeError: 'f' object has no attribute '__f'
 >>> dir(a)
['__class__', '__delattr__', '__dict__', '__doc__',  
'__getattribute__', '__hash__', '__init__', '__module__', '__new__',  
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__',  
'__weakref__', '_f__f']

As you see, it's there in the dict, but it's obfuscated - but that's  
all that other languages do anyway.  Anyone that takes advantage of  
that to get hold of members like this should have a very good reason  
for doing so.

Just think of a single leading underscore as protected, and double  
leading underscores as private, and you'll be fine.  As Simon said,  
people can still access these, but the consenting adults rule applies.

=Tony.Meyer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Will python never intend to support private, protected and public?

2005-09-28 Thread Tony Meyer
On 28/09/2005, at 11:54 PM, Paul Rubin wrote:

> Tony Meyer <[EMAIL PROTECTED]> writes:
>
>> I'm not sure why I haven't seen this mentioned yet, but a leading
>> double-underscore does really make a member private:...
>> As you see, it's there in the dict, but it's obfuscated - but that's
>> all that other languages do anyway.
>>
>
> No, that's false: [snip]

I didn't say *all* other languages, and I meant many other languages,  
although that's not clear from what I wrote.

=Tony.Meyer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Will python never intend to support private, protected and public?

2005-09-28 Thread Tony Meyer
On 28/09/2005, at 11:55 PM, Simon Brunning wrote:

> On 9/28/05, Tony Meyer <[EMAIL PROTECTED]> wrote:
>
>> I'm not sure why I haven't seen this mentioned yet, but a leading
>> double-underscore does really make a member private:
>>
>
> I thought about it, but I didn't mention it in the end because this
> feature ("name mangling") isn't intended as a mechanism for making
> things private - it's intended to prevent namespace clashes when doing
> multiple inheritance.

That's not what the documentation says:

"""
9.6 Private Variables

There is limited support for class-private identifiers.
[...]
Name mangling is intended to give classes an easy way to define  
``private'' instance variables and methods,
[...]
"""

<http://docs.python.org/tut/node11.html>

=Tony.Meyer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Will python never intend to support private, protected and public?

2005-09-28 Thread Tony Meyer
On 29/09/2005, at 3:45 AM, Fredrik Lundh wrote:

> Tony Meyer wrote:
>
>>> I thought about it, but I didn't mention it in the end because this
>>> feature ("name mangling") isn't intended as a mechanism for making
>>> things private - it's intended to prevent namespace clashes when  
>>> doing
>>> multiple inheritance.
>>
>> There is limited support for class-private identifiers.
>> [...]
>> Name mangling is intended to give classes an easy way to define
>> ``private'' instance variables and methods,
>> [...]
>> """
>
> the sentence you're quoting the first part of continues:
>
> without having to worry about instance variables defined by  
> derived
> classes

That elaborates on the intent, it doesn't change it.  The sentence  
clearly says that the intent is to easily define private variables,  
whereas Simon said that it the intent was not to provide a mechanism  
for making variables private.

> and the paragraph later says:
>
> Note that the mangling rules are designed mostly to avoid  
> accidents

That's explaining why you can still access the variables if you want  
to, not saying that this feature isn't meant to be used to indicate  
that a variable is private.

> and both sentences are from the *tutorial*, which doesn't exactly
> qualify as a design document.

A tutorial should not encourage users to use a feature in the wrong  
way, though.  If leading underscore(s) were not meant to indicate  
privateness, then the tutorial should not state that - this is where  
a large proportion of users learn Python; it's nonsensical to teach  
them something that's incorrect.

> if you want more rationale, here's the
> post that led to the current design:
>
> http://groups.google.com/group/comp.lang.python/msg/e79f875059d9a2ba
>
> "In my version, private data has it's own scope, so that name  
> clashes
> will not occur if a private with the same name is used in a  
> subclass."
>
> see the rest of that thread for more about the history of __.

Disagreeing with someone who actually took part in the discussion may  
not be a sensible idea but...

It's pretty clear to me from that thread that using a single/double  
underscore with variables *is* intended to indicate that the variable  
is private in some fashion.  As Guido pointed out:

 '*leading* underscore has a long tradition (in the C world,
 anyway, but we don't really want to ignore that here) of meaning
 "internal use" (of some kind)'

<http://groups.google.com/group/comp.lang.python/msg/edecfde2141f642b>

The name mangling lets one use private variables without having to  
worry about name clashes, but the purpose of the leading underscore 
(s) is to indicate that the variable is private

 "private seems to be useful because it offers a form of data
 hiding that's currently absent in Python"

<http://groups.google.com/group/comp.lang.python/msg/593533b57662438f>

as many people in that thread indicated that they were doing before  
this was proposed as an addition.

The OP wanted to know how to use private (and protected) variables in  
Python.  Even the FAQ has this answer:

 'Variables with double leading underscore are "mangled" to provide
 a simple but effective way to define class private variables.
 [...]
 This doesn't guarantee privacy: an outside user can still  
deliberately
 access the "_classname__spam" attribute, and private values are  
visible
 in the object's __dict__."

<http://www.python.org/doc/faq/programming.html#i-try-to-use-spam-and- 
i-get-an-error-about-someclassname-spam>

Which is basically what I said in my reply to the OP.  If this isn't  
the intent, then there's a lot of incorrect documentation, and a lot  
of incorrect c.l.p answers to this question in the past*.

=Tony.Meyer

* Well, there are no doubt a lot of incorrect c.l.p answers to any  
question :).  But anyway...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Moronicity of Guido van Rossum

2005-09-29 Thread Tony Meyer
On 30/09/2005, at 9:50 AM, Delaney, Timothy (Tim) wrote:

> You have to admit though, he's remarkably good at getting past
> Spambayes. Despite classifying *every* Xah Lee post as spam, he still
> manages to get most of his posts classified as 0% or 1% spam.

I can't believe that people are using c.l.p trolls as justification  
in their push to add white/black-listing to spambayes now .

I expect that if you look at the clues for such messages, you'll find  
that any 'Xah Lee' clues are swamped by lots of 'c.l.p message'  
clues.  A big problem with filtering mailing lists at the user end  
(rather than before the post is accepted) is that the mailing  
software adds so many strongly-correlated clues.  It's made worse  
because he uses so many words that you'd expect to find in legitimate  
c.l.p messages.

To fight this sort of message, I think spambayes would have to be  
able to understand the context more.

=Tony.Meyer

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


Re: A Moronicity of Guido van Rossum

2005-09-29 Thread Tony Meyer
> I know nobody wants to do add "white/black-listing", so we can do it
> probabilistically. In case it is not obvious, mailings with the words
> "jargon" or "moron" and their derrivatives should be flagged as 99.9%
> probability for Moronicity Xha Lee, Jargonizer, spam. If spam bayes  
> can't
> figure this out, then either it is not properly implemented or  
> Bayes himself
> was out to lunch.

I knew I'd regret my response .

The problem here isn't getting an appropriately spammy score for  
particular tokens, like Xah's name.  The problem is that the  
classifier has to taken into account the entire message, and the  
hammy clues outweigh the spammy ones (not unexpected, really,  
considering that other than all the trolling, the messages are  
reasonably on-topic).

This is a feature, not a bug.  It's the same feature that means that  
messages talking about spam on the spambayes mailing list, or the  
legitimate mail I get about viagra , get through to me.

=Tony.Meyer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Moronicity of Guido van Rossum

2005-09-30 Thread Tony Meyer
On 30/09/2005, at 10:56 PM, Gerrit Holl wrote:

> Tony Meyer wrote:
>
>> X-Spambayes-Classification: ham; 0.048
>> X-Spambayes-Evidence: '*H*': 0.90; '*S*': 0.00; 'bug.': 0.07;  
>> 'flagged': 0.07;
>> "i'd": 0.08; 'bayes': 0.09; 'from:addr:ihug.co.nz': 0.09;
>> 'really,': 0.09; 'cc:no real name:2**0': 0.14;
>> 'from:addr:t-meyer': 0.16; 'from:name:tony meyer': 0.16;
>> 'obvious,': 0.16; 'spambayes': 0.16; 'subject:Guido': 0.16;
>> 'trolling,': 0.16; 'regret': 0.82; 'lee,': 0.91; 'viagra': 0.91;
>> 'mailings': 0.93; 'probability': 0.93
>
>> This is a feature, not a bug.  It's the same feature that means that
>> messages talking about spam on the spambayes mailing list, or the
>> legitimate mail I get about viagra , get through to me.
>>
>
> True. However, most mail to this mailinglist has less than 0.001 spam
> probability. As you can see, this one had 0.048 - a vast score, almost
> enough to put it in my unsure box. It seems to be just not hammy  
> enough.
> It's interesting to see that no none of the foul language words  
> used by
> Xah Lee ever occurs in any spam I receive - spam is not that stupid.

Unless I'm misreading things, that's *my* message that scored 0.048  
(the "from:addr:ihug.co.nz", "from:name:tony meyer", and "spambayes"  
tokens make it seem that way)...

=Tony.Meyer

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


Unicode charmap decoders slow

2005-10-02 Thread Tony Nelson
Is there a faster way to decode from charmaps to utf-8 than unicode()?

I'm writing a small card-file program.  As a test, I use a 53 MB MBox 
file, in mac-roman encoding.  My program reads and parses the file into 
messages in about 3..5 seconds, but takes about 13.5 seconds to iterate 
over the cards and convert them to utf-8:

for i in xrange(len(cards)):
u = unicode(cards[i], encoding)
cards[i] = u.encode('utf-_8')

The time is nearly all in the unicode() call.  It's not so much how much 
time it takes, but that it takes 4 times as long as the real work, just 
to do table lookups.

Looking at the source (which, if I have it right, is 
PyUnicode_DecodeCharmap() in unicodeobject.c), I think it is doing a 
dictionary lookup for each character.  I would have thought that it 
would make and cache a LUT the size of the charmap (and hook the 
relevent dictionary stuff to delete the cached LUT if the dictionary is 
changed).

I thought of using U"".translate(), but the unicode version is defined 
to be slow.  Is there some similar approach?  I'm almost (but not quite) 
ready to try it in Pyrex.

I'm new to Python.  I didn't google anything relevent on python.org or 
in groups.

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


gtk.TextView.move_mark_onscreen() broken?

2005-10-02 Thread Tony Nelson
Is gtk.TextView.move_mark_onscreen() broken?  Perhaps only in Python's 
gtk module, in Python 2.3, gtk 2.4.14?  I'm asking here because I'm 
using gtk from Python and don't want to write a C program to verify my 
issue.  I've also tried gtk.TextView.scroll_to_mark() and 
gtk.TextView.place_cursor_onscreen(), and none of them want to do 
anything.  The rest of my program works, so I'm not a complete gtk bazo.

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode charmap decoders slow

2005-10-03 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:

> Tony Nelson wrote:
> > Is there a faster way to decode from charmaps to utf-8 than unicode()?
> 
> You could try the iconv codec, if your system supports iconv:
> 
> http://cvs.sourceforge.net/viewcvs.py/python-codecs/practicecodecs/iconv/

I had seen iconv.  Even if my system supports it and it is faster than 
Python's charmap decoder, it might not be available on other systems.  
Requiring something unusual in order to do a trivial LUT task isn't an 
acceptable solution.  If I write a charmap decoder as an extension 
module in Pyrex I can include it with the program.  I would prefer a 
solution that doesn't even need that, preferably in pure Python.  Since 
Python does all the hard wark so fast it certainly could do it, and it 
can almost do it with "".translate().

TonyN.:'[EMAIL PROTECTED]
  '  <http://www.georgeanelson.com/>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Unicode charmap decoders slow

2005-10-03 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:

> Tony Nelson wrote:
> > I had seen iconv.  Even if my system supports it and it is faster than 
> > Python's charmap decoder, it might not be available on other systems.  
> > Requiring something unusual in order to do a trivial LUT task isn't an 
> > acceptable solution.  If I write a charmap decoder as an extension 
> > module in Pyrex I can include it with the program.  I would prefer a 
> > solution that doesn't even need that, preferably in pure Python.  Since 
> > Python does all the hard wark so fast it certainly could do it, and it 
> > can almost do it with "".translate().
> 
> Well, did you try a pure-Python version yourself?
> 
> table = [chr(i).decode("mac-roman","replace") for i in range(256)]
> 
> def decode_mac_roman(s):
>  result = [table[ord(c)] for c in s]
>  return u"".join(result)
> 
> How much faster than the standard codec is that?

It's .18x faster.

TonyN.:'[EMAIL PROTECTED]
  '  <http://www.georgeanelson.com/>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Exception raising, and performance implications.

2005-10-03 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 "leo" <[EMAIL PROTECTED]> wrote:

> Hello all -
> 
> I was wondering about the performance implications of explicitly
> raising exceptions to get information about the current frame.
> Something like what the inspect module does, with:

Python uses exceptions internally, using StopIteration to terminate the 
iterator in a for: loop.

> ---
> def currentframe():
> """Return the frame object for the caller's stack frame."""
> try:
> raise 'catch me'
> except:
> return sys.exc_traceback.tb_frame.f_back
> ---

This also does a traceback; you might want to measure the cost of that.

> I come from a java background, where Exceptions are a big Avoid Me, but
> are the performance implications the same in Python? We're expecting a
> big load on our app (100,000 users/hour) , so we'd like to be as tuned
> as possible.

Switching to Python, eh?  Remember to measure, measure, measure!

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Controlling who can run an executable

2005-10-04 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 "Cigar" <[EMAIL PROTECTED]> wrote:

> I am developing a program for a client.  She runs a shop where her
> clients bring in items for sale or short term buyback.  Development of
> the program has been going great but she's mentioned that there is a
> 'feature' coming up in the next couple of weeks that she'd like me to
> implement that has me a bit worried.
> 
> My client has told me a story of how she hired someone from a competing
> store and that person had brought a copy of the program her competition
> was using to track clients and transactions.  He couldn't demonstrate
> the program for one reason or another because it was protected in a way
> that neither could circumvent. (She didn't remember how it was
> protected, she had hired this person a long time ago.)
> 
> Now that I'm three months into the development of this program, my
> client tells me she would like to protect her investment by preventing
> her employees from doing the same to her.  (Going to the competition
> and using her program.)
 ...

Call the competition and ask them what they used.  Point out that it 
worked.  If they won't tell you, just look at their software until you 
find out.

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C Wrapper Function, crashing Python?

2005-10-14 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 "Java and Swing" <[EMAIL PROTECTED]> wrote:

> one more update...
> 
> if I remove PyMem_Free and free(...) ...so no memory clean up...I can
> still only call doStuff 4 times, the 5th attemp crashes Python.
> 
> Java and Swing wrote:
> > update:
> > if I use C's free(result), free(a) free(b) instead of PyMem_Free...I
> > only get one successfuly use/call of doStuff.
> >
> > i.e.
> > // this works
> > doStuff(...)
> >
> > // python crashes here
> > doStuff(...)
> >
> > Java and Swing wrote:
> > > static PyObject *wrap_doStuff(PyObject *self, PyObject *args) {
> > >   // this will store the result in a Python object
> > >   PyObject *finalResult;
> > >
> > >   // get arguments from Python
> > >   char *result = 0;
> > >   char *in= 0;
> > >   char *aString = 0;
> > >   char *bString = 0;
> > >   MY_NUM *a;
> > >   MY_NUM *b;
> > >   int ok = PyArg_ParseTuple(args, "sss", &in, &aString, &bString);
> > >   if (!ok) return 0;
> > >
> > >   // do work to get a and b
> > >   // count - returns an int;  GetVal - returns a char *
> > >   a = GetVal(aString, count(aString, ","));
> > >   b = GetVal(bString, count(bString, ","));
> > >
> > >   // make function call, which returns a char *
> > >   result = doStuff(in, a, b);
> > >
> > >   // save result in Python string
> > >   finalResult = PyString_FromString(result);
> > >
> > >   // free memory
> > >   PyMem_Free(result);
> > >   PyMem_Free(a);
> > >   PyMem_Free(b);
> > >
> > >   // return the result as a Python string
> > >   return finalResult;
> > > }
> > >
> > > ...from python I can call this function 4 times...works fine.  WHen I
> > > call it for the fifth time python.exe crashes.  im thinking some memory
> > > problem in the wrapper function perhaps...but I am not sure.  The
> > > actually C function, doStuff can be called 5, 6,7...N times without a
> > > problem
> > > so i know its gotta be my wrapper.
> > > 
> > > Any ideas?  Thanks!
> 

I think your wrapper should look something like:

static PyObject *wrap_doStuff(PyObject *self, PyObject *args)
{
// this will store the result in a Python object
PyObject *finalResult;

// get arguments from Python
char *result = 0;
char *in= 0;
char *aString = 0;
char *bString = 0;
MY_NUM *a;
MY_NUM *b;

int ok = PyArg_ParseTuple(args, "sss", &in, &aString, &bString);
if (!ok) return 0;

// do work to get a and b
// count - returns an int;  GetVal - returns a char *
a = GetVal(aString, count(aString, ","));
b = GetVal(bString, count(bString, ","));

// make function call, which returns a char *
result = doStuff(in, a, b);

// save result in Python string
finalResult = PyString_FromString(result);

// free memory
free(result);
free(a);
free(b);

// return the result as a Python string
return finalResult;
}

You must match malloc() with free(), and PyMem_Malloc() with 
PyMem_Free().  Malloc() and free() usually crash /after/ the call that 
did the damage.  You may wish to avail yourself of your platform's 
malloc debugging facilities.

Note that I don't do this stuff in C, I do it in pyrex, and I'm new to 
it anyway, so there may still be something wrong.  Unless you are 
determined to learn how to do this in C, I think you should switch to 
pyrex.

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to make this code faster

2005-10-14 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

> def f(x,y):
> return math.sin(x*y) + 8 * x
> I have code like this:
> 
> def main():
> n = 2000
> a = zeros((n,n), Float)
> xcoor = arange(0,1,1/float(n))
> ycoor = arange(0,1,1/float(n))
> 
> 
> for i in range(n):
> for j in range(n):
> a[i,j] = f(xcoor[i], ycoor[j])  # f(x,y) = sin(x*y) + 8*x
> 
> print a[1000,1000]
> pass
> 
> if __name__ == '__main__':
> main()

I would guess that you are spending most of your time calculating 
sin(x*y).  To find out, just replace f(x,y) with 1, which will produce 
wrong results really fast, and see what that does to your execution time.

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can module access global from __main__?

2005-10-14 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 "Neal  Norwitz" <[EMAIL PROTECTED]> wrote:

> Steve Holden wrote:
> > Neal Becker wrote:
> > >
> > > Still curious about the answer.  If I know that I am imported from 
> > > __main__,
> > > then I can do access X as sys.modules[__main__].X.  In general, I don't
> > > know how to determine who is importing me.
> > >
> > I don't think you can without huge amounts of introspection - it's even
> > worse than the "what's the name of this object" question that seems to
> > come up regularly.
> 
> import sys
> 
> frame = sys._getframe()
> caller = frame.f_back
> print 'Called from', caller.f_code.co_filename, caller.f_lineno
> # for more info, look into the traceback module
> 
> > A module can be imported from multiple modules, and
> > you only get to execute code on the first import.
> > Even then (on the first import) I am not sure how you could introspect
> > to find the answer you want.
> 
> You can install your own __import__() hook to catch all imports.
> 
> Just because you can do something, it doesn't follow that you should do
> it, especially in this case.  Unless you really, really need these
> tricks, they shouldn't be used.

Neal, I have a similar question (in that maybe I shouldn't do 
something), and you seem to know your way around modules, so I'll just 
butt in.  If this isn't OK I'll post as a new thread.

I have written a python module that uses some C functions.  I wrote the 
module in two parts, one python, one pyrex (C).  They need to share some 
globals.  (I use pyrex to handle ref counting.  I think I'm glad I did.)

At first they just sort of mutually imported each other, and it worked 
until I put tests in the python one and set it up to run them when it 
was __main__.  This reminded me that there are also other ways modules 
can be imported under different names, so I tried a different approach.

Now I'm just shoving references to the python module's globals into the 
pyrex module (first defining them in the pyrex module).  The pyrex 
module doesn't import the python module anymore.  This also works, even 
when the python module has a different name ("__main__").  I just feel 
dirty about it.

How does one normally make a module that uses some functions in C?  Will 
that approach work with pyrex?  With globals?

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] Speed up Charmap codecs with fastcharmap module

2005-10-16 Thread Tony Nelson
Fastcharmap is a python extension module that speeds up Charmap codecs 
by about 5 times.

 

Usage:

import fastcharmap
fastcharmap.hook('codec_name')

Fastcharmap will then speed up calls that use that codec, such as 
unicode(str, 'codec_name') and str.encode('codec_name'), and won't 
interfere with Charmap codecs that haven't been hooked.

Documentation is in PyDoc form:

import fastcharmap
help(fastcharmap)

Fastcharmap is available as a standard Python source tarball, binary 
tarball, and RPMs.  It isn't packaged for MSWindows yet (maybe soon), or 
for MOSX.  It is written in Python and Pyrex 0.9.3, but builds from .c 
source when Pyrex is not available.  A C compiler is required for source 
installs.  I have only used it with Python 2.3.4 on FC3 Linux, but it 
should work on Python 2.4 and on other platforms.

As fastcharmap is an extension module, it might not be available on a 
particular computer.  I handle that this way in a program of mine:

try:
import fastcharmap
except ImportError:
print "fastcharmap not available"
else:
fastcharmap.hook('mac_roman')

This is done on document open, which on Gnome / GTK is chatty anyway.

I wrote fastcharmap when I found that decoding a large amount of text 
was taking 3 times as long as loading the document from a file.  Python 
should be fast!  The application is a simple card-file program that can 
also open mbox files as cards.  I am using a 50 MB test file from a Mac 
that loads in about 4 seconds on my computer (wow!), and was decoding in 
about 13 seconds.  Now it takes 2 seconds to decode or encode.

Python developers are working on faster Charmap codecs for a future 
version of Python.  Fastcharmap may be useful until then, and shouldn't 
cause any problems when the new codecs are available.

As this is my first Python module, I'd like some experienced module 
authors and packagers to comment on it, before I make it into cheese.

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do you draw this layout with wxpython?

2005-10-17 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 "Young H. Rhiu" <[EMAIL PROTECTED]> wrote:

> See: http://hilug.org/img/app_layout.GIF
> 
> I'm implementing an album-like application with wxpython but I'm new to
> wxPython though I know how to program with python. The problem is that
> it's not easy for me to deal with drawing layout stuff with wxpython.
> What layout I'm thinking of looks like the gif image above.
> 
> The application is about saving some comments for each pictures on the
> filesystem. There are two windows. The above one is a window for
> loading some images and the below one is a TextCtrl for writing
> comments and if img1, for instance, is clicked, the first notebook(?)
> folder should be active.
> 
> Below is the program I tried but I don't know how to attach a notebook
> window under the image window.
> Any help is greatly appreciated.
> 
> Thanks in Advance, Rhiu
> 
> My Code:
> from wxPython.wx import *
> 
> class smallAppFrame(wxFrame):
> def __init__(self, parent, id, title):
> wxFrame.__init__(self, parent = None, id = -1,
>  title = "MySmallApp", pos = wxPoint(200, 200),
>  size = wxSize(460, 200), style =
> wxDEFAULT_FRAME_STYLE)
> 
> self.bitmap01 = wxStaticBitmap(self, -1,
> wxEmptyBitmap(100,100))
> self.bitmap02 = wxStaticBitmap(self, -1,
> wxEmptyBitmap(100,100))
> self.bitmap03 = wxStaticBitmap(self, -1,
> wxEmptyBitmap(100,100))
> self.bitmap04 = wxStaticBitmap(self, -1,
> wxEmptyBitmap(100,100))
> 
> box = wxBoxSizer(wxHORIZONTAL)
> 
> box.Add((10,10))
> box.Add(self.bitmap01, 0, wxALIGN_CENTER)
> box.Add((10,10))
> box.Add(self.bitmap02, 0, wxALIGN_CENTER)
> box.Add((10,10))
> box.Add(self.bitmap03, 0, wxALIGN_CENTER)
> box.Add((10,10))
> box.Add(self.bitmap04, 0, wxALIGN_CENTER)
> box.Add((10,10))
> 
> self.SetAutoLayout(True)
> self.SetSizer(box)
> 
> class MySmallApp(wxApp):
> def OnInit(self):
> frame = smallAppFrame(None, -1, "MySmallApp")
> frame.Show(true)
> self.SetTopWindow(frame)
> return true
> 
> app = MySmallApp(0)
> app.MainLoop()

I've never used (or learned) wxWidgets, and I'm even new to GTK, but I 
think you just need a deeper structure.  SmallAppFrame() would contain 
two subwindows, probably using something like wxBoxSizer(wxVERTICAL).  
The top subwindow would contain what you've done now, and the bottom one 
would have the rest of your stuff.

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stripping ASCII codes when parsing

2005-10-17 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 David Pratt <[EMAIL PROTECTED]> wrote:

> I am working with a text format that advises to strip any ascii control 
> characters (0 - 30) as part of parsing data and also the ascii pipe 
> character (124) from the data. I think many of these characters are 
> from a different time. Since I have never seen most of these characters 
> in text I am not sure how these first 30 control characters are all 
> represented (other than say tab (\t), newline(\n), line return(\r) ) so 
> what should I do to remove these characters if they are ever 
> encountered. Many thanks.

Most of those characters are hard to see.

Represent arbitrary characters in a string in hex: "\x00\x01\x02" or 
with chr(n).

If you just want to remove some characters, look into "".translate().  

nullxlate = "".join([chr(n) for n in xrange(256)])
delchars = nullxlate[:31] + chr(124)
outputstr = inputstr.translate(nullxlate, delchars)

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Mutual module imports

2005-10-17 Thread Tony Nelson
How does one normally make a Python extension module that has some parts 
in Python and some functions in C share globals between the Python and C 
functions?  Will that approach work with Pyrex?

I have written a Python module that uses some C functions.  I wrote the 
module in two parts, one Python, one Pyrex (C).  They need to share some 
globals.  (I use pyrex to handle ref counting.  I think I'm glad I did.)

At first they just sort of mutually imported each other, and it worked 
until I put tests in the Python one and set it up to run them when it is 
named "__main__".  What happened reminded me that there are also other 
ways modules can be imported under different names, so I tried a 
different approach.

Now the Python module imports the Pyrex module and just shoves 
references to its globals into the Pyrex module (the Pyrex module 
defines them as None).  The Pyrex module doesn't import the Python 
module anymore.  This also works, even when the Python module has a 
different name (e.g. "__main__").  I just feel dirty about it.

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stripping ASCII codes when parsing

2005-10-17 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 David Pratt <[EMAIL PROTECTED]> wrote:

> This is very nice :-)  Thank you Tony.  I think this will be the way to  
> go.  My concern ATM is where it will be best to unicode. The data after  
> this will go into dict and a few processes and into database. Because  
> input source if not explicit encoding, I will have to assume ISO-8859-1  
> I believe but could well be cp1252 for most part ( because it says no  
> ASCII (0-30) but alright ASCII chars 128-254) and because most are  
> Windows users.  Am thinking to unicode after stripping these characters  
> and validating text, then unicoding (utf-8) so it is unicode in dict.  
> Then when I perform these other processes it should be uniform and then  
> it will go into database as unicode.  I think this should be ok.

Definitely "".translate() then unicode().  See the docs for 
"".translate().  As far as charset, well, if you can't know in advance 
you'll want to have some way to configure it for when it's wrong.  Also, 
maybe 255 is not allowed and should be checked for?

TonyN.:'[EMAIL PROTECTED]
  '  <http://www.georgeanelson.com/>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] Re: output from external commands

2005-10-24 Thread Tony Meyer
On 25/10/2005, at 3:36 PM, Steven Bethard wrote:

> I wouldn't fret too much about a sharp remark from Fredrik Lundh.
> They're pretty much all that way. ;) [...] It takes a little  
> training to get used to
> him, but if you can look past the nasty bite, he's really a valuable
> resource around here.

+1 QOTW :)

=Tony.Meyer

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


Re: How best to reference parameters.

2005-10-25 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 "David Poundall" <[EMAIL PROTECTED]> wrote:

> I am writing a scada package that has a significant amount of user
> defined parameters stored in text files that I wish to cleanly access
> in code.  By way of an example, a few lines from the configuration file
> would typically be ...
> 
> [Plant Outputs]
> Y0P1  Pump 1 Pressure
> Y1P2  Pump 2 Fluid Transfer Pump
> Y2P3  Pump 3 Vac Pump
> Y3P4  Pump 4 Vac Pump
> Y4P5  Pump 5 / Pump 1B
> Y5P6  Pump 6 / Pump 2B
> Y6M
> Y7D
> Y10   E
> Y11   F
> 
> I can read these values in as dictionary items and refernce them in
> code like this...
> 
> Y['P4'] = 1   # Which will ultimately switch my pump on
> Y['P3'] = 0   # Which will ultimately switch my pump off
> 
> but I would much rather reference the plant outputs like this ...
> 
> Y.P4 = 1
> Y.P3 = 0
 ...

d = {'a':1, 'b':2, 'c':3}

class foo:
def __init__(self, d):
self.__dict__.update(d)

f = foo(d)

print f.a, f.b, f.c

(retyped from memory)

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Any Pythonic GTK Undo library?

2005-10-29 Thread Tony Nelson
I'm looking for a "pythonic" GTK Undo library/class.  It would have a 
framework for Undo/Redo, and would provide Undo/Redo for TextView, 
Entry, and containers and other classes.  In a "batteries included" 
fashion, just instantiating a "UndoableTextView" or "UndoableEntry" or 
"UndoableContainer" would provide Undo and Redo in the right-click menu; 
simply connecting such an object to an "UndoableUIManager" would take 
care of the stock items in the menus and toolbar; and there would be a 
simple connection to some sort of "UndoableDocument" interface or mix-in 
for more global sequencing of Undo/Redo.  Does something like this exist 
for Python or GTK?  Googling didn't turn up anything useful.

I'm disappointed that GTK doesn't do this already.  Making my own seems 
doable, but a fair amount of work.  If there isn't some such thing 
already, is there interest in using one that I make?

I know about GUndo, which doesn't implement any actual undo operations; 
the actual operations would need to be coded for TextView and Entry and 
anything else.

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any Pythonic GTK Undo library?

2005-10-29 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 Dave Cook <[EMAIL PROTECTED]> wrote:

> On 2005-10-29, Tony Nelson <[EMAIL PROTECTED]> wrote:
> 
> > I'm looking for a "pythonic" GTK Undo library/class.  It would have a 
> 
> You might ask the authors of Kiwi if they plan to add undo/redo.  Or help
> them add it if you can.
> 
> http://www.async.com.br/projects/kiwi/
> 

Well, after I implement it myself, if I do, I could give them the code 
to port to kiwi.


> It would be great to have this feature in the Gtk C API, though.  I do see
> some relevant bugzilla entries:
> 
> http://bugzilla.gnome.org/show_bug.cgi?id=316551
> 
> You might want to make a new request for a general undo/redo interface.

Well, after I implement it myself, if I do, I could give them the code 
to translate to C.

TonyN.:'[EMAIL PROTECTED]
  '  <http://www.georgeanelson.com/>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Scanning a file

2005-10-30 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:

> Steve Holden wrote:
> > Indeed, but reading one byte at a time is about the slowest way to
> > process a file, in Python or any other language, because it fails to
> > amortize the overhead cost of function calls over many characters.
> >
> > Buffering wasn't invented because early programmers had nothing better
> > to occupy their minds, remember :-)
> 
> Buffer, and then read one byte at a time from the buffer.

Have you mesured it?

#!/usr/bin/python
'''Time some file scanning.
'''

import sys, time

f = open(sys.argv[1])
t = time.time()
while True:
b = f.read(256*1024)
if not b:
break
print 'initial read', time.time() - t
f.close()

f = open(sys.argv[1])
t = time.time()
while True:
b = f.read(256*1024)
if not b:
break
print 'second read', time.time() - t
f.close()

if 1:
f = open(sys.argv[1])
t = time.time()
while True:
b = f.read(256*1024)
if not b:
break
for c in b:
pass
print 'third chars', time.time() - t
f.close()

f = open(sys.argv[1])
t = time.time()
n = 0
srch = '\x00\x00\x01\x00'
laplen = len(srch)-1
lap = ''
while True:
b = f.read(256*1024)
if not b:
break
n += (lap+b[:laplen]).count(srch)
n += b.count(srch)
lap = b[-laplen:]
print 'fourth scan', time.time() - t, n
f.close()


On my (old) system, with a 512 MB file so it won't all buffer, the 
second time I get:

initial read 14.513395071
second read 14.8771388531
third chars 178.250257969
fourth scan 26.1602909565 1

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NTFS reparse points

2005-11-03 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 Stanislaw Findeisen <[EMAIL PROTECTED]> wrote:
 ...
> However I can't see FILE_ATTRIBUTE_REPARSE_POINT turned on in any file / 
> directory shortcuts I create. In fact the only attribute set in 
> shortcuts created using Windows Explorer is FILE_ATTRIBUTE_ARCHIVE. (I 
> am using GetFileAttributes() to examine this.)
 ...

Shortcuts are files with a .lnk extention.  Reparse points are NTFS 
directory data.

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: when and how do you use Self?

2005-11-04 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 "Tieche Bruce A MSgt USMTM/AFD" <[EMAIL PROTECTED]> 
 wrote:

> I am new to python,

> Could someone explain (in English) how and when to use self?

> I have been reading, and haven't found a good example/explanation

 is a good explanation of just about all of 
Python.  You should read it.  It explains when to use "self".

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ? MDI depreciated

2005-11-06 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 "LenS" <[EMAIL PROTECTED]> wrote:

> Hate to ask this dum question (since I've been hiding under a rock).
> But if the MDI UI model is/was depreciated.  What is the new UI model.
> 
> Would love some links that explain in gerneral and specific terms.

In article <[EMAIL PROTECTED]>,
 "Brendan" <[EMAIL PROTECTED]> wrote:

> This is probably a question better suited for a wxPython or MSDN
> newsgroup.  What OS are you referring to?  What GUI toolkit are you
> using?
> 
> Microsoft's office on Windows has moved to a model where every document
> has its own toolbar, menubar, and taskbar entry.  Windows developers
> tend to mimic MS Office, so many are also moving to this model. Mac
> apps have never had MDI.

MS also uses a "Tabbed" version of MDI where only one document at a time 
is visible.  Sometimes this is /implemented/ using the MDI APIs (and 
they also have some MDI apps that don't use the APIs; go figure).  Gnome 
uses Tabbed windows as well; see Gedit, which opens documents in tabs, 
though they can be dragged out into their own windows.  In GTK, at 
least, the Tabbed interface is easily done as a Notebook.

MacOS apps used MDI from the beginning of Multifinder; it just worked 
better than on MSWindows because instead of a grey background you got to 
see the rest of the desktop and the other apps.  On MacOS, MDI was 
referred to as "Layers".  If on MSWindows MDI windows were always 
maximized, had no grey background, and hid the MDI Frame when not in 
front, they would be almost exactly what MacOS did.

MOSX, being a version of NextOS and NextStep, has the more "advanced" 
no-layer, no-MDI UI, and Apple recommends that each app should have only 
one window.

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Validate string as UTF-8?

2005-11-06 Thread Tony Nelson
I'd like to have a fast way to validate large amounts of string data as 
being UTF-8.

I don't see a fast way to do it in Python, though:

unicode(s,'utf-8').encode('utf-8)

seems to notice at least some of the time (the unicode() part works but 
the encode() part bombs).  I don't consider a RE based solution to be 
fast.  GLib provides a routine to do this, and I am using GTK so it's 
included in there somewhere, but I don't see a way to call GLib 
routines.  I don't want to write another extension module.

Is there a (fast) Python function to validate UTF-8 data?

Is there some other fast way to validate UTF-8 data?

Is there a general way to call GLib functions?

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Validate string as UTF-8?

2005-11-06 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 david mugnai <[EMAIL PROTECTED]> wrote:

> On Sun, 06 Nov 2005 18:58:50 +, Tony Nelson wrote:
> 
> [snip]
> 
> > Is there a general way to call GLib functions?
> 
> ctypes?
> http://starship.python.net/crew/theller/ctypes/

Umm.  Might be easier to write an extension module.

TonyN.:'[EMAIL PROTECTED]
  '  <http://www.georgeanelson.com/>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Validate string as UTF-8?

2005-11-06 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 "Fredrik Lundh" <[EMAIL PROTECTED]> wrote:

> Tony Nelson wrote:
> 
> > I'd like to have a fast way to validate large amounts of string data as
> > being UTF-8.
> 
> define "validate".

All data conforms to the UTF-8 encoding format.  I can stand if someone 
has made data that impersonates UTF-8 that isn't really Unicode.


> > I don't see a fast way to do it in Python, though:
> >
> > unicode(s,'utf-8').encode('utf-8)
> 
> if "validate" means "make sure the byte stream doesn't use invalid
> sequences", a plain
> 
> unicode(s, "utf-8")
> 
> should be sufficient.

You are correct.  I misunderstood what was happening in my code.  I 
apologise for wasting bandwidth and your time (and I wasted my own time 
as well).

Indeed, unicode(s, 'utf-8') will catch the problem and is fast enough 
for my purpose, adding about 25% to the time to load a file.

TonyN.:'[EMAIL PROTECTED]
  '  <http://www.georgeanelson.com/>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: modifying small chunks from long string

2005-11-14 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 "MackS" <[EMAIL PROTECTED]> wrote:

> Hello everyone
> 
> I am faced with the following problem. For the first time I've asked
> myself "might this actually be easier to code in C rather than in
> python?", and I am not looking at device drivers. : )
> 
> This program is meant to process relatively long strings (10-20 MB) by
> selectively modifying small chunks one at a time. Eg, it locates
> approx. 1000-2000 characters and modifies them. Currently I was doing
> this using a string object but it is getting very slow: although I only
> modify a tiny bit of the string at a time, a new entire string gets
> created whenever I "merge" it with the rest. Eg,
> 
> shortstr = longstr[beg:end]
> 
> # edit shortstr...
> 
> longstr = longstr[:beg] + shortstr + longstr[end:] # new huge string is
> created!!
> 
> Can I get over this performance problem without reimplementing the
> whole thing using a barebones list object? I though I was being "smart"
> by avoiding editing the long list, but then it struck me that I am
> creating a second object of the same size when I put the modified
> shorter string in place...

A couple of minutes experimenting with array.array at the python command 
line indicates that it will work fine for you.  Quite snappy on a 16 MB 
array, including a slice assignment of 1 KB near the beginning.  
Array.array is probably better than lists for speed, and uses less 
memory.  It is the way to go if you are going to be randomly editing all 
over the place but don't need to convert to string often.

MutableString warns that it is very slow.  It seems to work by having a 
string data item that it keeps replacing.  I didn't try it.


> shortstr = longstr[beg:end]
> 
> # edit shortstr...
> 
> longstr = longstr[:beg] + shortstr + longstr[end:] # new huge string is
> created!!

Replace this with slice assignment:

longarray = array.array('c',longstr) # once only at beginning!

shortstring = longarray[beg:end].tostring() # or just edit an array

# edit shortstring (or shortarray)

longarray[beg:end] = array.array('c',shortstr)

longstring = longarray.tostring() # if needed

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


python-dev Summary for 2005-09-01 to 2005-09-15

2005-11-16 Thread Tony Meyer
005-September/055983.html>`__
- `gdbinit problem <http://mail.python.org/pipermail/python-dev/2005- 
September/056178.html>`__
- `Exception Reorg PEP checked in <http://mail.python.org/pipermail/ 
python-dev/2005-September/056296.html>`__
- `international python <http://mail.python.org/pipermail/python-dev/ 
2005-September/056326.html>`__
- `SIGPIPE => SIG_IGN? <http://mail.python.org/pipermail/python- 
dev/2005-September/056341.html>`__
- `[draft] python-dev Summary for 2005-08-16 through 2005-08-31  
<http://mail.python.org/pipermail/python-dev/2005-September/ 
056348.html>`__
- `[Python-checkins] python/dist/src/Lib urllib.py, 1.169, 1.170  
<http://mail.python.org/pipermail/python-dev/2005-September/ 
056349.html>`__
- `Wanting to learn <http://mail.python.org/pipermail/python-dev/2005- 
September/056350.html>`__
- `Python code.interact() and UTF-8 locale <http://mail.python.org/ 
pipermail/python-dev/2005-September/056361.html>`__
- `pygettext() without newlines (Was: Re: Replacement for print in  
Python 3.0) <http://mail.python.org/pipermail/python-dev/2005- 
September/056368.html>`__
- `Python 3 executable name (was: Re: PEP 3000 and iterators) `__
- `Python 3 executable name <http://mail.python.org/pipermail/python- 
dev/2005-September/056371.html>`__
- `Skiping searching throw dictionaries of mro() members. `__
- `Fwd: [Python-checkins] python/dist/src/Misc NEWS, 1.1193.2.94,  
1.1193.2.95 <http://mail.python.org/pipermail/python-dev/2005- 
September/056405.html>`__
- `[Python-checkins] python/dist/src/Lib/test regrtest.py, 1.171,  
1.172 test_ioctl.py, 1.2, 1.3 <http://mail.python.org/pipermail/ 
python-dev/2005-September/056406.html>`__
- `python/dist/src/Lib urllib.py, 1.165.2.1, 1.165.2.2 `__
- `Variant of removing GIL. <http://mail.python.org/pipermail/python- 
dev/2005-September/056423.html>`__
- `Compatibility between Python 2.3.x and Python 2.4.x `__
- `Example for "property" violates "Python is not a one pass  
compiler" <http://mail.python.org/pipermail/python-dev/2005-September/ 
056190.html>`__
- `python optimization <http://mail.python.org/pipermail/python-dev/ 
2005-September/056425.html>`__





Epilogue


This is a summary of traffic on the `python-dev mailing list`_ from
September 01, 2005 through September 15, 2005.
It is intended to inform the wider Python community of on-going
developments on the list on a semi-monthly basis.  An archive_ of
previous summaries is available online.

An `RSS feed`_ of the titles of the summaries is available.
You can also watch comp.lang.python or comp.lang.python.announce for
new summaries (or through their email gateways of python-list or
python-announce, respectively, as found at http://mail.python.org).

This is the 3rd summary written by the python-dev summary pairing of
Steve Bethard and Tony Meyer (Tempus Fugit!).

To contact us, please send email:

- Steve Bethard (steven.bethard at gmail.com)
- Tony Meyer (tony.meyer at gmail.com)

Do *not* post to comp.lang.python if you wish to reach us.

The `Python Software Foundation`_ is the non-profit organization that
holds the intellectual property for Python.  It also tries to advance
the development and use of Python.  If you find the python-dev Summary
helpful please consider making a donation.  You can make a donation at
http://python.org/psf/donations.html .  Every penny helps so even a
small donation with a credit card, check, or by PayPal helps.



Commenting on Topics


To comment on anything mentioned here, just post to
`comp.lang.python`_ (or email python-list@python.org which is a
gateway to the newsgroup) with a subject line mentioning what you are
discussing.  All python-dev members are interested in seeing ideas
discussed by the community, so don't hesitate to take a stance on
something.  And if all of this really interests you then get involved
and join `python-dev`_!


-
How to Read the Summaries
-

The in-development version of the documentation for Python can be
found at http://www.python.org/dev/doc/devel/ and should be used when
looking up any documentation for new code; otherwise use the current
documentation as found at http://docs.python.org/ .  PEPs (Python
Enhancement Proposals) are located at http://www.python.org/peps/ .
To view files in the Python CVS online, go to
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/ .  Reported
bugs and suggested patches can be found at the SourceForge_ project
page.

Please note that this summary is written using reStructuredText_.
Any unfamiliar punctuation is probably markup for reST_ (otherwise it
is probably regular expression syntax or a typo =); you can safely
ignore it.  We do suggest learning reST, though; it's simple and is
accepted for `PEP markup`_ and can be turned into many different
formats 

newbie question: 'import site' failed; use -v for traceback

2005-11-17 Thread Tony Gill



Hi,
 
I've just downloaded 
and installed Python 2.4.2 for Windows and am having troubling getting 
started.
 
My system is: MS 
Windows XP Pro SP2
 
When I run 'python 
(command line)' from the start menu the first line in the CMD window 
is:
'import site' 
failed; use -v for traceback
 
This seems to be 
causing other problems; for example: when I type 'import os' at the prompt I get the 
error:
 
Traceback (most 
recent call last):  File "", line 1, in ?ImportError: 
No module named os
 
Also I cannot run 
the IDLE (Python GUI) from the start menu either. Nothing loads. I presume my 
problems all come back to the fact that import site fails when python 
starts.
 
Any help getting me 
started greatly appreciated.
 
Thanks
 
Tony
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: python-dev summary

2005-11-17 Thread Tony Meyer
On 17/11/2005, at 7:20 PM, Titus Brown wrote:

>> [The HTML version of this Summary is available at
>> http://www.python.org/dev/summary/2005-09-01_2005-09-15.html]
>
> no... no, it's not ;)

Sorry; I should amend the copy that's posted to say "will be  
available".  The summaries get posted here, to python-announce, and  
sent to Brett to be put online.  The one here appears immediately,  
the python-announce one appears whenever a moderator has time to  
approve it, and the one online appears when Brett has time to put it up.

=Tony.Meyer

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


Re: Python Library Reference - question

2005-11-17 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:

> The "Python LIbrary Reference" at
> http://docs.python.org/lib/contents.html seems to be an important
> document. I have two questions
> 
> Q1. How do you search inside "Python LibraryReference" ? Does it exist
> in pdf or chm form?
 ...

I use Google:

site:docs.python.org/lib foo bar

Note that Google is pretty flexible about what is a "site".  
"docs.python.org/lib", "docs.python.org", and "python.org" are all 
"sites", so you can zoom in and out as needed.

The other suggestions look good, too.

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


os.path.expanduser('~/foo') and MSWindows "My Documents"

2005-11-17 Thread Tony Nelson
On *nix, ~/foo refers to a file in a user's home directory.  On 
MSWindows, users normally look at "My Documents" in their home 
directory.  ISTM that a file that my program would put in ~/. on Linux 
should be put in "~/My Documents/" (modulo os.path.normpath()) on 
MSWindows, where a user would expect it.  How do you guys cope with this 
issue?

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hot to split string literals that will across two or more lines ?

2005-11-17 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 "Sam Pointon" <[EMAIL PROTECTED]> wrote:

> > print "a string which is very loo" \
> > + "ong."
> 
> Minor pedantry, but the plus sign is redundant. Python automatically
> concatenates string literals on the same logical line separated by only
> whitespace.
> 

While we're at it, I use bracketing instead of line continuation:

print ( "a long string, longer than this "
"and some more of the string" )

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.expanduser('~/foo') and MSWindows "My Documents"

2005-11-17 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:

> Try this:
> 
> 
> from win32com.shell import shell, shellcon
> HOMEDIR = shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_PERSONAL)
> myfile_location = os.path.join(HOMEDIR, myfile_name)
> 
> Define a HOMEDIR for your various platforms (use sys.platform to figure
> out what choice to make) and the rest of your code should not need to
> care where "home" is...

Sounds good, thanks.  I'll read up on it all tomorrow.

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.expanduser('~/foo') and MSWindows "My Documents"

2005-11-18 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:

> python
> 
> >>> import os
> >>> help(os.path.expanduser)
> >>> import platform
> >>> platform.system()
> 'Windows'
> >>> platform.release()
> 'XP'
> >>>

platform looks good.

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


python-dev Summary for 2005-10-01 through 2005-10-15

2005-11-21 Thread Tony Meyer
Title: python-dev Summary for 2005-10-01 through 2005-10-15Content-type: text/x-rstEncoding: utf-8python-dev Summary for 2005-10-01 through 2005-10-15
.. contents::[The HTML version of this Summary is available athttp://www.python.org/dev/summary/2005-10-01_2005-10-15.html]
=Announcements=QOTF: Quote of the FortnightFrom Phillip J. Eby:    So, if threads are "easy" in Python compared to other
    langauges, it's *because of* the GIL, not in spite of it.Contributing thread:- `Pythonic concurrency <http://mail.python.org/pipermail/python-dev/2005-October/057062.html
>`__[SJB]GCC/G++ Issues on Linux: Patch availableChristoph Ludwig provided the previously `promised patch`_ to address some of the issues in compiling Python with GCC/G++ on Linux.  The patch_ keeps ELF systems like x86 / Linux from having any dependencies on the C++ runtime, and allows systems that require main() to be a C++ function to be configured appropriately.
.. _promised patch: http://www.python.org/dev/summary/2005-07-01_2005-07-15.html#gcc-g-issues-on-linux.. _patch: 
http://python.org/sf/1324762Contributing thread:- `[C++-sig] GCC version compatibility <
http://mail.python.org/pipermail/python-dev/2005-October/057230.html>`__[SJB]=Summaries=-Concurrency in Python-
Michael Sparks spent a bit of time descibing the current state and future goals of the Kamaelia_ project.  Mainly, Kamaelia aims to make concurrency as simple and easy to use as possible.  A scheduler manages a set of generators that communicate with each other through Queues.  The long term goals include being able to farm the various generators off into thread or processes as needed, so that whether your concurrency model is cooperative, threaded or process-based, your code can basically look the same.
There was also continued discussion about how "easy" threads are.  Shane Hathaway made the point that it's actually locking that's "insanely difficult", and approaches that simplify how much you need to think about locking can keep threading relatively easy -- this was one of the strong points of ZODB.  A fairly large camp also got behind the claim that threads are easy if you're limited to only message passing.  There were also a few comments about how Python makes threading easier, 
e.g. through the GIL (see `QOTF: Quote of the Fortnight`_) and through threading.threads's encapsulation of thread-local resources as instance attributes... _Kamaelia: http://kamaelia.sourceforge.ne
Contributing threads:- `Pythonic concurrency - cooperative MT <http://mail.python.org/pipermail/python-dev/2005-October/056898.html
>`__- `Pythonic concurrency <http://mail.python.org/pipermail/python-dev/2005-October/057023.html>`__[SJB]
-Organization of modules for threading-A few people took issue with the current organization of the threading modules into Queue, thread and threading.  Guido views Queue as an application of threading, so putting it in the threading module is inappropriate (though with a deeper package structure, it should definitely be a sibling).  Nick Coghlan suggested that Queue should be in a threadtools module (in parallel with itertools), while Skip proposed a hierarchy of modules with thread and lock being in the lowest level one, and Thread and Queue being in the highest level.  Aahz suggested (and Guido approved) deprecating the thread module and renaming it to _thread at least in Python 
3.0.  It seems the deprecation may happen sooner though.Contributing threads:- `Making Queue.Queue easier to use <http://mail.python.org/pipermail/python-dev/2005-October/057184.html
>`__- `Autoloading? (Making Queue.Queue easier to use) <http://mail.python.org/pipermail/python-dev/2005-October/057216.html
>`__- `threadtools (was Re: Autoloading? (Making Queue.Queue easier to use)) <http://mail.python.org/pipermail/python-dev/2005-October/057262.html
>`__- `Threading and synchronization primitives <http://mail.python.org/pipermail/python-dev/2005-October/057269.html>`__
[SJB]-Speed of Unicode decoding-Tony Nelson found that decoding with a codec like mac-roman or iso8859-1 can take around ten times as long as decoding with utf-8.  Walter Dörwald provided a patch_ that implements the mapping using a unicode string of length 256 where undefined characters are mapped to u"\ufffd".  This dropped the decode time for mac-roman to nearly the speed of the utf-8 decoding.  Hye-Shik Chang showed off a fastmap decoder with comparable performance.  In the end, Walter's patch was accepted.
.. patch: h

Re: Using gettext to provide different language-version of a script

2005-11-22 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 "Thomas W" <[EMAIL PROTECTED]> wrote:

> I'm trying to wrap my head around the docs at python.org related to the
> gettext-module, but I'm having some problem getting it to work. Is
> there any really simple, step-by-step on how to use this module
> available?
> 
> This is my script so far :
> 
> import gettext
> gettext.install('test2', '.', unicode=1)
> lang1 = gettext.translation('test2', languages=['no'])
> print  _('writing a log to file')

I do:

# assume the script is named "myscript.py":
us = os.path.splitext(os.path.basename(sys.argv[0]))[0]
usdir = os.path.dirname(sys.argv[0])

import gettext
gettext.install(us, usdir)


> in the folder where the test2.py-script lives I've created a
> folder-structure like
> 
> ./locales/NO/LC_MESSAGES/messages.mo

Mine looks like:

./en_PL/LC_MESSAGES/myscript.mo


> the messages.mo-file I've created using the scripts in the
> \Tools\i18l\-folder by running :
> 
> python pygettext.py test2.py
> 
> and renaming the generated messages.pot-file to messages.po, and
> editing it to look like :
> 
> # SOME DESCRIPTIVE TITLE.
> # Copyright (C) YEAR ORGANIZATION
> # FIRST AUTHOR <[EMAIL PROTECTED]>, YEAR.
> #
> msgid ""
> msgstr ""
> "Project-Id-Version: PACKAGE VERSION\n"
> "POT-Creation-Date: 2005-11-22 13:02+W. Europe Standard Time\n"
> "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
> "Last-Translator: FULL NAME <[EMAIL PROTECTED]>\n"
> "Language-Team: LANGUAGE <[EMAIL PROTECTED]>\n"
> "MIME-Version: 1.0\n"
> "Content-Type: text/plain; charset=CHARSET\n"
> "Content-Transfer-Encoding: ENCODING\n"
> "Generated-By: pygettext.py 1.5\n"
 ...

You need to set the "Content-Type: charset" and 
"Content-Transfer-Encoding:".  I use:

"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mixed types and variants

2005-11-23 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:

 ...
> - Maybe someone here can suggest some other variant type, or some other
> solution.

Pyrex?  Pyrex is mostly like Python with the possibility of C types.  It 
handles mixed types just like Python, and the C code it produces is sort 
of readable.

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ncurses' Dark Devilry

2005-11-29 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 Jeremy Moles <[EMAIL PROTECTED]> wrote:

> I'm working on a project using ncurses w/ Python. As an aside, I
> implemented addchstr in the cursesmodule.c file in Python SVN, if anyone
> wants me to try and get that made permanent.
> 
> AT ANY RATE...
> 
> I was wondering--and this is more a general curses question rather than
> a Python one, but I know there are some old-timers here who have made
> curses obey before--is there a way to "repaint" a portion of screen
> without stealing the "cursor?" That is:
> 
> I have a focus "wheel" of sorts that allows the user to do input on
> various wigets and windows and whatnot. However, if I want to quickly
> call addstr somewhere else in the application I have to:
> 
>   1. Store the YX coords of the cursor currently
>   2. Use the cursor in the "current" action
>   3. Restore the old cursor location
> 
> I know there are ways around this as I have seen curses apps that, for
> example, have a clock that updates every second without stealing
> "focus."
> 
> I tried implementing/using addchstr (mentioned above) to no success.
> 
> Any ideas? Is this just the plain wrong place to ask this? :)

I've only tried to read the Python Library Curses docs, but I thought 
that the Window object method addstr() would do what you want.

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unicode speed

2005-11-29 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 David Siroky <[EMAIL PROTECTED]> wrote:

> Hi!
> 
> I need to enlighten myself in Python unicode speed and implementation.
> 
> My platform is AMD [EMAIL PROTECTED] (x86-32), Debian, Python 2.4.
> 
> First a simple example (and time results):
> 
> x = "a"*5000
> real0m0.195s
> user0m0.144s
> sys 0m0.046s
> 
> x = u"a"*5000
> real0m2.477s
> user0m2.119s
> sys 0m0.225s
> 
> So my first question is why creation of a unicode string lasts more then 10x
> longer than non-unicode string?

Your first example uses about 50 MB.  Your second uses about 200 MB, (or 
100 MB if your Python is compiled oddly).  Check the size of Unicode 
chars by:

>>> import sys
>>> hex(sys.maxunicode)

If it says '0x10' each unichar uses 4 bytes; if it says '0x', 
each unichar uses 2 bytes.


> Another situation: speed problem with long strings
> 
> I have a simple function for removing diacritics from a string:
> 
> #!/usr/bin/python2.4
> # -*- coding: UTF-8 -*-
> 
> import unicodedata
> 
> def no_diacritics(line):
> if type(line) != unicode:
> line = unicode(line, 'utf-8')
> 
> line = unicodedata.normalize('NFKD', line)
> 
> output = ''
> for c in line:
> if not unicodedata.combining(c):
> output += c
> return output
> 
> Now the calling sequence (and time results):
> 
> for i in xrange(1):
> x = u"a"*5
> y = no_diacritics(x)
> 
> real0m17.021s
> user0m11.139s
> sys 0m5.116s
> 
> for i in xrange(5):
> x = u"a"*1
> y = no_diacritics(x)
> 
> real0m0.548s
> user0m0.502s
> sys 0m0.004s
> 
> In both cases the total amount of data is equal but when I use shorter strings
> it is much faster. Maybe it has nothing to do with Python unicode but I would
> like to know the reason.

It has to do with how strings (either kind) are implemented.  Strings 
are "immutable", so string concatination is done by making a new string 
that has the concatenated value, ans assigning it to the left-hand-side.  
Often, it is faster (but more memory intensive) to append to a list and 
then at the end do a u''.join(mylist).  See GvR's essay on optimization 
at .

Alternatively, you could use array.array from the Python Library (it's 
easy) to get something "just as good as" mutable strings.

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython : getting started

2005-11-29 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 David Sulc <[EMAIL PROTECTED]> wrote:

> Hi !
> 
> I've looked all over (internet, books, etc.) and I haven't found a very 
> good ressource to get started with wxPython (yes, I've been through 
> their tutorial).
> 
> What I would basically like to do for starters is to be able to define 
> the main panel being displayed. For example :
> 1. wxFrame contains a wxPanel  (call it mainPanel).
> 2. mainPanel contains another panel (childPanelA)
> 3. another panel has been defined (childPanelB) but is not displayed 
> (the user can only see childPanelA inside mainPanel)
> 4. by clicking on a menu entry (for example), the displayed panel is now 
> childPanelA (which is inside mainPanel)
> 
> So how do I do this ? I realize it's a very basic question, but it's 
> been driving me mad...
 ...

I don't know or use wxWidgets, and I've just learned GTK, but I think 
one good answer is the same as with GTK:  use a wxNotebook.  You may be 
able to hide the tabs, or you may just decide they're a good thing to 
have.

To do what you asked, see the wxWindow method Show(), which you would 
call for each or A and B etc. in response to the command.

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Pydoc: restrict base class doc?

2005-11-30 Thread Tony Nelson
I'd like to prevent Pydoc from adding base class documentation for some 
of my classes.  Specifically, I have a couple of classes that derive 
from GTK widgets, and dumping all that documentation in doesn't have 
much benefit.  Is there some thing I can do in my source, or to Pydoc, 
to tell it to skip some base classes?

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


How to keep Pydoc from listing too much?

2005-12-02 Thread Tony Nelson
How can I tell Pydoc not to list information for some of the base 
classes?  For example, when a class inherits from gtk.Widget, lots of 
GTK stuff gets added that doesn't really need to be there.  Is there 
some option to Pydoc to tell it to skip some classes?  Is there 
something I can put in my source that is a hint to Pydoc?

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: Dao Language v.0.9.6-beta is release!

2005-12-02 Thread Tony Nelson
In article <[EMAIL PROTECTED]>,
 Dave Hansen <[EMAIL PROTECTED]> wrote:

> On 2 Dec 2005 10:08:21 -0800 in comp.lang.python, [EMAIL PROTECTED]
> wrote:
> 
> >Here it is again...  Python bypassed/discounted because, of all things,
> >scoping by indentation!?!?
> >
> >This used to surprise me.  Until I hear more and more otherwise
> >reasonable programmers list this as their number one reason for
> >shunning Python.
> >
> >I gauge design defects by how much after market
> >discussion/documentation a feature generates/requires.   Scoping by
> >indentation is a whopper of a defect.
> 
> FWIW, indentation scoping one one of the features that _attracted_ me
> to Python.

Me too.  Or rather, Python code is much more readable because every 
nincompoop has to use indentation correctly whether they want to or not, 
and I like readable code.

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


os.rename copies when old is in-use - is this deliberate?

2005-12-03 Thread Tony Meyer
On Windows, if I do os.rename(old, new) where old is a file that is
in-use (e.g. python itself, or a dll that is loaded), I would expect
that an error would be raised (e.g. as when os.remove is called with
an in-use file).  However, what happens is that a copy of the file is
made, and the old file still exists.

For example:

C:\>c:\python24\python.exe
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import sys
>>> sys.executable
'c:\\python24\\python.exe'
>>> os.rename(sys.executable, "d:\\python24.exe")
>>> ^Z

D:\>dir c:\python24\p*.exe
 Volume in drive C is ACER
 Volume Serial Number is 320D-180E

 Directory of c:\python24

28/09/2005  12:41 p.m. 4,608 python.exe
28/09/2005  12:41 p.m. 5,120 pythonw.exe
   2 File(s)  9,728 bytes
   0 Dir(s)  16,018,685,952 bytes free

C:\>dir d:\p*24.exe
 Volume in drive D is DATA
 Volume Serial Number is 4019-78E0

 Directory of d:\

28/09/2005  12:41 p.m. 4,608 python24.exe
   1 File(s)  4,608 bytes
   0 Dir(s)  15,362,207,744 bytes free

Is this the intended behaviour?  The documentation doesn't give any
indication that it is (so unless I'm missing something, this is at
least a documentation bug).

Any insight appreciated :)  (I do know that I can work around it by
doing a remove after the rename, if the file exists).

=Tony.Meyer
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   4   >