Re: Regular expressions, help?

2012-04-19 Thread Andy
If you plan on doing more work with regular expressions in the future and you 
have access to a Windows machine you may want to consider picking up a copy of 
RegxBuddy. I don't have any affiliation with the makers but I have been using 
the software for a few years and it has saved me a lot of frustration.

Thanks,
 -Andy-


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


Re: Internet Data Handling » mailbox

2016-10-22 Thread andy
Fri, 21 Oct 2016 22:43:55 -0400 wrote Adam Jensen:

> The mailbox library documentation seems to be a little weak. In this
> example:
> 
> https://docs.python.org/2.7/library/mailbox.html#examples
> 
> import mailbox for message in mailbox.mbox('~/mbox'):
> subject = message['subject']   # Could possibly be None.
> if subject and 'python' in subject.lower():
> print subject
> 
> What is the structure of "message"? I guess it's a dictionary but what
> is its structure? What are the keys? Is the structure constant or does
> it change depending upon the content of the mbox?
> 
> I'm a bit new to python documentation. How would a potential user of the
> "mailbox" library determine these things? Or did I miss something?

I would type: help(mailbox) after importing it.

best regards
andy
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Internet Data Handling » mailbox

2016-10-23 Thread andy
Sat, 22 Oct 2016 19:41:45 -0400 wrote Adam Jensen:

> On 10/22/2016 05:47 AM, andy wrote:
>> I would type: help(mailbox) after importing it.
> 
> I guess the output of that might be more meaningful once I understand
> the underlying structures and conventions.

yes - you are right. fortunatelly python autors have thought about 
'documntation strings' and 'coding style', the syntax of python itself 
helps reading source code (indentation). this allows using auto-
documentation features like help(...).

when i don't know enough about a module like 'mailbox' , i first try a 
file search for the source code on the local system: i.e. 'locate 
mailbox.py' on a linux system. possibly i have to install the module 
first when there is nothing found (using pip or package manager).

this yields on my system ('sudo updatedb' - for updating the db) to this 
result:

/usr/lib/python2.7/mailbox.py
/usr/lib/python2.7/mailbox.pyc
/usr/lib/python3.5/mailbox.py

i can read the source file with: 'less /usr/lib/python3.5/mailbox.py'.
within the sourcefile i can study the imports and data structures.

Other sources of information: doc.python.org - even with search:
https://docs.python.org/3/search.html?q=mailbox

and finally all these mail-modules should follow the RFCs ;-)
https://tools.ietf.org/html/rfc2822

best regards
andy
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to print variable few time?

2016-11-13 Thread andy
Sat, 12 Nov 2016 04:58:20 -0800 wrote guy asor:

> hello!
> 
> this is my code:
> 
> word=raw_input()
> print word*3
> 
> 
> with this code im getting - wordwordword.
> what changes i need to make to get - word word word - instead?
> 
> thanks

using python3.x:

word=input()
print((word+' ')*2, end='')
print(word)

 ..but D'Apranos ' '.join(..) is far more elegant.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to print variable few time?

2016-11-13 Thread andy
Sun, 13 Nov 2016 15:12:01 +0100 wrote andy:

> word=input()
> print((word+' ')*2, end='')
> print(word)
> 
>  ..but D'Apranos ' '.join(..) is far more elegant.

don't know whether I really would use this form, but it works in python3:

word = ' '.join([input()]*3)
print(word)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to print variable few time?

2016-11-16 Thread andy
Sun, 13 Nov 2016 17:27:23 +0200 wrote Jussi Piitulainen:


>>> word=raw_input()
>>> print word*3
>>> 
>>> 
>>> with this code im getting - wordwordword.
>>> what changes i need to make to get - word word word - instead?
>>> 
>>> thanks
>>
>> using python3.x:
>>
>> word=input()
>> print((word+' ')*2, end='')
>> print(word)
> 
> print(*[word]*3)

thanks for this starred expression - it took me one afternoon to 
understand ;-)

one should search the library and https://www.python.org/dev/peps/
pep-0448/ and try to

>>> import this

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


printing funny symbols within spyder ide

2016-11-24 Thread andy
when printing these 'escaped-number-texts' within Linux/Spyder3 ide 
console, i get funny symbols like a "phone-symbol", triangles or symbols 
for male or female.

>>> print("\7") # gives a phone
>>> print("\5")
>>> print("\1")
>>> print("\21")
>>> print("\30")
>>> print("\31")
>>> print("\32")

def phonesymbol():
print("\7")

phonesymbol() # prints a phone symbol

my question is, is this a bug or a feature of Spyder3?
if it is a feature, where can I find the complete table of symbols?

within bash - starting python3 - i get some ugly "unicode?" symbols, 
which look like a square containig tiny alphanumeric numbers.

best regards
andy
-- 
https://mail.python.org/mailman/listinfo/python-list


What's the best python web-developer's editor

2005-01-20 Thread andy
Anybody like to comment on which editor they use for python web app 
development - for both discrete and mixed python and html code,  and why?

I'm comfortable with IDLE (used it for years) but of course it lacks ftp 
or webDAV abilities, obviously because it's not intended for that type 
of use.

I've had a look at Screem - and that seems to do python syntax 
highlighting, but it dosn't seem to be python syntax aware (unless 
there's a hidden option somewhere).  Although I can live without auto 
indent, I'd rather not...

I'm sure emacs, xemacs, vi, elvis and so on can do the same, but I have 
no experience with them for  heavy python or html coding, nor the time 
to trip off down a blind-alley to find out!  I know Enough Vi To Get 
By(tm) but it's by no means my favourite editor.  Emacs is a complete 
mystery to me.

I guess I *could* use IDLE and Screem together, but that's a clunky 
solution!

all opinions greatfully received,
-andyj
--
http://mail.python.org/mailman/listinfo/python-list


unit test nested functions

2005-07-23 Thread Andy
How can you unit test nested functions?  Or do you have to pull them out to 
unit test them, which basically means I will never use nested functions.

Also, same thing with private member functions protected by __.  Seems like 
there is a conflict there between using these features and unit testing.

Andy


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


3 weeks to go to Python-UK!

2005-04-01 Thread andy
There are just three weeks to go to Python-UK!
The UK Python conference is once again taking place at the
Randolph Hotel in the centre of historic Oxford, as part of
the ACCU conference, on 21-23 April.
   http://www.accu.org/conference/python.html
On Tuesday 19th there's also a full day tutorial for intermediate
and advanced Python programmers, given by Michele Simionato,
at a fraction of the price of most professional training courses.
There are just a few places remaining, so book quickly!
   http://www.accu.org/conference/python_tutorial.html
Anyone attending the event is free to move between tracks and learn
from a world-class program on patterns, agile development,
Java, C++ and C# as well as Python.
Best Regards,
Andy Robinson
Python-UK Conference chair
--
http://mail.python.org/mailman/listinfo/python-list


Ten days to go until Python-UK...

2005-04-11 Thread andy
This is a reminder that there are just ten days left before the UK 
Python
Conference.  This is the one chance in the UK each year to hear 
in-depth
talks on a wide variety of topics from top Python experts. It
takes place at the Randolph Hotel in Oxford on 21-23 April.

https://www.accu.org/conference/python.html
The Python event is part of the ACCU Conference which is one of the 
world's
leading events on C++, Java, patterns and development methods.

We are very happy to announce that Greg Stein will be flying in to
talk about "Python at Google" as our keynote talk.  We've got a
great array of talks on language features, GUIs, network programming,
testing tools, PyPy; and case studies and expertise from many of the 
key Python
companies and projects including Google, the BBC, SchoolTool, PyPy,
AB Strakt, Clocksoft and ReportLab.

Places are limited, so please register now at...
   https://www.accu.org/bookings/
Best Regards,
Andy Robinson
ACCU Python Conference Chair
--
http://mail.python.org/mailman/listinfo/python-list


Nokia to speak at Python-UK next week

2005-04-14 Thread andy
I am please to announce that Tapio Tallgren of Nokia Research
Labs is coming to Python-UK to talk about Python on the Nokia Series
60 phones.  If you want to get hands-on, upgrade that handset now!
This is a late addition to an already star-studded programme including
Greg Stein of Google, and many other key Python speakers and
projects.
Python-UK is part of the ACCU conference, Randolph Hotel,
Oxford, 21-23 April  (i.e. Thursday to Saturday next week).
There's still time to sign up and attend the event, in its entirety
or on a day by day basis!
  http://www.accu.org/conference/python.html
Best Regards,
Andy Robinson
Python-UK conference chair
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to lock a file in ftp site

2005-12-19 Thread andy
[EMAIL PROTECTED] wrote:

>hi all
>
>am trying to write some information into the file, which is located in
>ftp, and this file can be updated by number of people, but if at all i
>download a file from the ftp to my local machine, update it and then
>upload it back to ftp, and at the same time if some one else downloads
>the same file for the modification, then the data will be overwritten.
>
>so is there a way in Python script where i can lock the file, so that
>no one updates it until i release the lock.
>
>Or is there a way where i can directly update the file from the ftp
>itself, i mean without downloading it to my local machine.
>
>Thanks in advance for the help
>
>regards
>yogi
>
>  
>
I've come across this problem - instead of uploading the file to it's

intended directory, upload it to a temp directory, with a unique name
(say ummddhhmmss where u is username and the rest are
obvious) and then *rename* it to it's correct name in the real
destination directory. Do the move in a try... except block and if it
fails, take evasive action.

In FTP a rename (i.e. move) is usually an atomic action but an upload is
not. You have an unavoidable race condition here trying to lock a file
(even if ftp allowed it) but with the method described above, you can
avoid it, but get the same effect.

Hope that helps!
-andyj

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


Re: problem adding list values

2005-12-22 Thread andy
David M. Synck wrote:

>Hi all, 
>
>I am fairly new to Python and trying to figure out a syntax error
>concerning lists and iteration through the same. What I am trying to do is
>sum a list of float values and store the sum in a variable for use later.
>
>The relevant code looks like this -
>
>def getCredits():
>
>""" This function asks the user to input any credits not shown on their 
> bank statement
>
>It returns the sum(converted to float) of the entered credits """
>
>global credits
>credlist = []
>credits = 0.0
>temp = 0.0
>print "Now you need to enter any credits not shown on your bank statement 
> \n"
>print "Please enter a zero (0) once all credits have been entered \n"
>raw_input("Hit 'Enter' to continue \n")
>temp = float(raw_input("Please enter the first credit \n"))
>
>while temp != 0:
>credlist.append(temp)
>temp = float(raw_input("Please enter the next credit \n"))
>   
>i = 0
>for i in credlist:
>credits += credlist[i]
>i = i + 1
>
>return credits
>
>And the syntax error I get is this - 
>
>Traceback (most recent call last):
>  File "./BankReconciler_Rev1.py", line 129, in ?
>main()
>  File "./BankReconciler_Rev1.py", line 116, in main
>getCredits()
>  File "./BankReconciler_Rev1.py", line 60, in getCredits
>credits += credlist[i]
>TypeError: list indices must be integers
>
>
>If anyone can point me in the right direction, I would greatly appreciate
>it.
>
>Thanks in advance
>  
>
Your problem is here:

i = 0 
for i in credlist:  
credits += credlist[i]
i = i + 1

In the for loop, i is successively bound to each element in credlist
(which are floats) and you then try to index credlist with each element
in turn: you can't index lists with floats, so you get an error.

Try inserting a print command just before the credits expression, and
you'll see what I mean:

i = 0 
for i in credlist:  
print i
credits += credlist[i]
i = i + 1


What you probably mean is:

credits = 0.0
for i in credlist:
credits += i

However, you should really use:

credits = sum(credlist)

It's far faster and more "pythonic".

NOTE: Although it may be easy to think of Python lists as arrays,
they're more than that. The Python for loop moves through a list,
binding (think assigning) the loop variable (in this case "i") to each
*element* of the list at a time on successive iterations, viz:

>>> for i in ["apples","oranges","grapes","pears","tomatoes"]:
... print i
apples
oranges
grapes
pears
tomatoes
>>>

Hope that helps ;-)

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


command text parsing and hints displaying on user input.

2006-10-16 Thread Andy
Hi guys,

I'm writing a program with a feature of accepting user input as command
text and parsing it to correct function calls...example:

"5 minutes later"/"5 min later"/"5 minute later"/"after 5 minutes"...
are being parsed as the same rule so the system will call a later
function with minutes=5 as parameter.

Of course there are many other possiblilities, "seconds"/"days", and
even "every(each) hour"/"every Monday"/"every two days"...so on...

The datetime computation can be done with the wonderful "dateutil"
package, but I'm not sure with the command text parsing part. I could
do a lot of regular expression, but it'll be great if there is already
something similar available...or even a hint that can make it easier
than hand-writing a lot of regular expression code...

Another requirment is to display useful hints when user input the
command text. Example:

user input:"5" -> hints: "5 minutes later/5 hours later/5 days
later/every 5 minutes"
user input:"fi" -> hints: "next Friday"/"first thing tommorrow"
user input:"ne" -> hints: "next day"/"next hour"/"next week"/"next
month"

Sounds too intelligent to do? Any advices on this?

Thanks guys.

Andy

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


Re: command text parsing and hints displaying on user input.

2006-10-16 Thread Andy
Anybody have an idea on this??
Does Natural Language Processing help in this case?

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


How do I find possible matches using regular expression?

2006-11-23 Thread Andy
Hi there,

I'm trying to do some predicting work over user input, here's my
question:

for pattern r'match me', the string 'no' will definitely fail to match,
but 'ma' still has a chance if user keep on inputting characters after
'ma', so how do I mark 'ma' as a possible match string?

Thanks a lot,

Andy

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

Re: How do I find possible matches using regular expression?

2006-11-23 Thread Andy
The problem is the input will be much more complex than the example, it
could be something like "30 minutes later" where any string starting
with a number is a possible match.


Paul McGuire 寫道:

> "Andy" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Hi there,
> >
> > I'm trying to do some predicting work over user input, here's my
> > question:
> >
> > for pattern r'match me', the string 'no' will definitely fail to match,
> > but 'ma' still has a chance if user keep on inputting characters after
> > 'ma', so how do I mark 'ma' as a possible match string?
> >
> > Thanks a lot,
> >
> > Andy
> >
> Maybe .startsWith might be more useful than re.match, since you are
> predicting user input based on characters that have been typed so far.
> 
> -- Paul

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

Re: How do I find possible matches using regular expression?

2006-11-23 Thread Andy
OK, here's what I want...

I'm doing a auto-tasking tool in which user can specify the execution
rule by inputting English instead of a complex GUI interface(Normally a
combination of many controls). This way is way better user interaction.

So the problem comes down to "understanding" user input and
"suggesting" possible inputs when user is writing a rule.

Rules will be like "30 minutes later", "Next Monday", "Every 3 hours",
"3pm"...Sure this is an infinite collection, but it doesn't have to be
perfect , it might make mistakes given inputs like "10 minutes after
Every Monday noon".

The "suggesting" feature is even harder, I'm still investigating
possibilities.

Tried NLTK_Lite, I'm sure it can understands well a good user input,
but it is not doing good with some bad inputs("2 hours later here"),
bad inputs makes the toolkit fails to parse it. And NLTK also does not
help on the suggesting part.

Now I'm thinking manipulating regular expressions. I think it's
possible to come up with a collection of REs to understand basic
execution rules. And the question is again how to do suggestions with
the RE collection.

Any thoughts on this subject?

I'm not a native English speaker so...please, be mistake tolerant with
my post here:-)




"Fredrik Lundh 写道:
"
> Andy wrote:
>
> > The problem is the input will be much more complex than the example, it
> > could be something like "30 minutes later" where any string starting
> > with a number is a possible match.
>
> so if I type "1", are you going to suggest all possible numbers
> that start with that digit?  doesn't strike me as very practical.
>
> maybe you could post a more detailed example, where you clearly
> explain what a pattern is and how it is defined, what prediction
> means, and what you want to happen as new input arrives, so we
> don't have to guess?
> 
> 

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

Re: How do I find possible matches using regular expression?

2006-11-23 Thread Andy
The seems good to me, I'll try it out, thanks for the posting.


"Peter Otten 写道:
"
> Andy wrote:
>
> > I'm trying to do some predicting work over user input, here's my
> > question:
> >
> > for pattern r'match me', the string 'no' will definitely fail to match,
> > but 'ma' still has a chance if user keep on inputting characters after
> > 'ma', so how do I mark 'ma' as a possible match string?
>
> The following may or may not work in the real world:
>
> import re
>
> def parts(regex, flags=0):
> candidates = []
> for stop in reversed(range(1, len(regex)+1)):
> partial = regex[:stop]
> try:
> r = re.compile(partial + "$", flags)
> except re.error:
> pass
> else:
> candidates.append(r)
> candidates.reverse()
> return candidates
>
> if __name__ == "__main__":
> candidates = parts(r"[a-z]+\s*=\s*\d+", re.IGNORECASE)
> def check(*args):
> s = var.get()
> for c in candidates:
> m = c.match(s)
> if m:
> entry.configure(foreground="#008000")
> break
> else:
> entry.configure(foreground="red")
>
>
> import Tkinter as tk
> root = tk.Tk()
> var = tk.StringVar()
> var.trace_variable("w", check)
> entry = tk.Entry(textvariable=var)
> entry.pack()
> root.mainloop()
>
> The example lets you write an assignment of a numerical value, e. g
>
> meaning = 42
>
> and colours the text in green or red for legal/illegal entries.
> 
> Peter

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

Re: How do I find possible matches using regular expression?

2006-11-23 Thread Andy
This works well as a checking strategy, but what I want is a suggesting
list...

Maybe what I want is not practical at all?

Thanks anyway Peter.

Andy Wu


Andy ��道:

> The seems good to me, I'll try it out, thanks for the posting.
>
>
> "Peter Otten 写道:
> "
> > Andy wrote:
> >
> > > I'm trying to do some predicting work over user input, here's my
> > > question:
> > >
> > > for pattern r'match me', the string 'no' will definitely fail to match,
> > > but 'ma' still has a chance if user keep on inputting characters after
> > > 'ma', so how do I mark 'ma' as a possible match string?
> >
> > The following may or may not work in the real world:
> >
> > import re
> >
> > def parts(regex, flags=0):
> > candidates = []
> > for stop in reversed(range(1, len(regex)+1)):
> > partial = regex[:stop]
> > try:
> > r = re.compile(partial + "$", flags)
> > except re.error:
> > pass
> > else:
> > candidates.append(r)
> > candidates.reverse()
> > return candidates
> >
> > if __name__ == "__main__":
> > candidates = parts(r"[a-z]+\s*=\s*\d+", re.IGNORECASE)
> > def check(*args):
> > s = var.get()
> > for c in candidates:
> > m = c.match(s)
> > if m:
> > entry.configure(foreground="#008000")
> > break
> > else:
> > entry.configure(foreground="red")
> >
> >
> > import Tkinter as tk
> > root = tk.Tk()
> > var = tk.StringVar()
> > var.trace_variable("w", check)
> > entry = tk.Entry(textvariable=var)
> > entry.pack()
> > root.mainloop()
> >
> > The example lets you write an assignment of a numerical value, e. g
> >
> > meaning = 42
> >
> > and colours the text in green or red for legal/illegal entries.
> > 
> > Peter

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

Quick and dirty dialogs?

2005-05-02 Thread andy
What's the easiest way for a script to throw up simple dialogs such as
file select and alerts?

I thought there was something in the standard library that didn't need
TK and was cross-platform but I can't seem to get my Google-fu working
well enough to find it.

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


Re: Quick and dirty dialogs?

2005-05-02 Thread andy
By 'not needing TK' I meant 2 things:

1. Is there a one liner/no brainer as I'm short on time and, yes,
didn't want to start fiddling with anything new (normally I'd leap at
the opportunity ;-)

2. I couldn't remember if TK is installed by default on a vanilla OS X
install. My script is going to have to run there without very much time
for testing.

So. I should have asked specifically about TK on OS X shouldn't I! Does
anyone happen to know off hand?


Robert Brewer wrote:
> [EMAIL PROTECTED] wrote:
> > What's the easiest way for a script to throw up simple dialogs such
as
> > file select and alerts?
> >
> > I thought there was something in the standard library that didn't
need
> > TK and was cross-platform but I can't seem to get my Google-fu
working
> > well enough to find it.
>
> If by "didn't need TK" you mean "I don't want to have to learn Tk",
try
> Steve Ferg's EasyGUI:
>
> http://www.ferg.org/easygui/
> 
> 
> Robert Brewer
> MIS
> Amor Ministries
> [EMAIL PROTECTED]

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


Re: Quick and dirty dialogs?

2005-05-02 Thread andy
Stopped being lazy and found the TK answer myself. (it needs some extra
stuff installed. see the macpython site's faq for info). Still be
interested to know if there is a sem-cross-platform solution to simple
dialogs that doesn't need TK...

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


new string function suggestion

2005-06-13 Thread Andy
What do people think of this?

'prefixed string'.lchop('prefix') == 'ed string'
'string with suffix'.rchop('suffix') == 'string with '
'prefix and suffix.chop('prefix', 'suffix') == ' and '

The names are analogous to strip, rstrip, and lstrip.  But the functionality 
is basically this:

def lchop(self, prefix):
  assert self.startswith(prefix)
  return self[len(prefix):]

def rchop(self, suffix):
  assert self.endswith(suffix)
  return self[:-len(suffix]

def chop(self, prefix, suffix):
  assert self.startswith(prefix)
  assert self.endswith(suffix)
  return self[len(prefix):-len(suffix]

The assert can be a raise of an appropriate exception instead.  I find this 
to be a very common need, and often newbies assume that the 
strip/lstrip/rstrip family behaves like this, but of course they don't.

I get tired of writing stuff like:

if path.startswith('html/'):
  path = path[len('html/'):]
elif s.startswith('text/'):
  path = path[len('text/'):]

It just gets tedious, and there is duplication.  Instead I could just write:

try:
  path = path.lchop('html/')
  path = path.lchop('text/')
except SomeException:
  pass

Does anyone else find this to be a common need?  Has this been suggested 
before?

Andy


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


String formatting for complex writing systems

2007-06-27 Thread Andy
Hi guys,

I'm writing a piece of software for some Thai friend.  At the end it
is supposed to print on paper some report with tables of text and
numbers.  When I test it in English, the columns are aligned nicely,
but when he tests it with Thai data, the columns are all crooked.

The problem here is that in the Thai writing system some times two or
more characters together might take one single space, for example งิ
(u"\u0E07\u0E34").  This is why when I use something like u"%10s"
% ..., it just doesn't work as expected.

Is anybody aware of an alternative string format function that can
deal with this kind of writing properly?

Any suggestion is highly appreciated.  Thanks!
Andy

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

Re: String formatting for complex writing systems

2007-07-02 Thread Andy
Thanks guys!

I've used the HTML and the unicodedata suggestions, each on a
different report.  These worked nicely!

Andy

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


Re: *** Watch BOMBSHELL video of Senator John Kerry admitting 911 was in INSIDE JOB ???

2007-04-24 Thread Andy
On 23 Apr 2007 21:12:45 -0700, [EMAIL PROTECTED] wrote:

>http://www.911blogger.com/node/8053
>
>Senator John Kerry was questioned concerning 9/11 during an appearance
>at Book People in Austin, Texas. Members of Austin 9/11 Truth Now
>asked Kerry about the officially unexplained collapse of WTC Building
>7."
>
>Kerry responded:
>
>"I do know that that wall, I remember, was in danger and I think
>they made the decision based on the danger that it had in destroying
>other things-- that they did it in a controlled fashion."
>
>http://www.jonesreport.com/articles/220407_kerry_wtc7.html
>
>Thanks to the dozen or so people who submitted this as a blog entry :)
>
>"Mr. Kerry?!?"
>
>"Just a follow-up or two...
>
>WHAT THE HELL|?| Are you saying that building was wired that day? Or
>well in advance? 'Splain, please.
>
>Does your fellow Bonesman George Walker Bush appreciate you letting
>the cat out of the bag on this? Is that your cell phone I hear
>ringing?
>
>Why is your wife squirming like that? Stop it, Theresa! Stop it!"

This is much more funny.

http://www.youtube.com/watch?v=HCkYfYa8ePI&mode=related&search=
-- 
http://mail.python.org/mailman/listinfo/python-list


List objects are un-hashable

2007-04-27 Thread Andy
Hi, I'm trying to search and print any no# of Python keywords present
in a text file (say - foo.txt), and getting the above error. Sad for
not being able to decipher such a simple problem (I can come up with
other ways - but want to fix this one FFS). Any help is appreciated.
Thanks!!

import keyword, re, sys, string
inp = open("foo.txt", "r")
words,lines = 0, 0

for line in inp:
lines +=1
# a list of words
tempwords = line.split(None)
if keyword.iskeyword(tempwords):
print tempwords

inp.close()

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


Re: List objects are un-hashable

2007-04-27 Thread Andy

> What you want is something like:
>
>  for line in inp:
>  lines +=1
>  # a list of words
>  tempwords = line.split()
>  for k in tempwords:
>  if keyword.iskeyword(k):
> print tempwords


I think it should be:

 if keyword.iskeyword(k):
  print k

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


Re: List objects are un-hashable

2007-04-29 Thread Andy
Thanks Michael and Ant.

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


Counting

2007-04-29 Thread Andy
Hi, the file below will print all the keywords in a file and also the
line # of the keyword. What I couldn't figure out is to count those
keywords per line. For example - "Line #1 has 3 keywords"

Can I do like -

total[j] = total[j] + numwords(k)
"Line number %d has %d keywords" % (j, total[j])

Seems sort of "illegal" in Python?



-
import keyword, sys, string, fileinput
def numwords(s):
list = string.split(s)
return len(list)

# Get the file name either from the command-line or the user
if len(sys.argv) != 2:
   name = raw_input("Enter the file name: ")
else:
   name = sys.argv[1]

inp = open(name,"r")
linelist = inp.readlines()
total, words,lines = 0, 0, 0

for i in range(len(linelist)):
line = linelist[i]
tempwords = line.split()
for k in tempwords:
if keyword.iskeyword(k):
total = total + numwords(k)
j = i + 1
print" The word * %s * belongs in line number: %d" % (k,
j)

print "Total keywords in this file are: %d" %(total)

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


Re: Counting

2007-04-29 Thread Andy
I pretty doubt about this - "c = line.count(k)" I might wanna recheck
on that.
-
I think it would be obvious how to write this:

for i,line in enumerate(linelist):
   line = line.split()
   for k in line:
 if keyword.iskeyword(k):
   c = line.count(k)
   total += line.count(k)
   print "Line #%d has %d keywords." % (i+1, c)
   break

print "Total keyords are: %d" % total

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


Re: Counting

2007-04-29 Thread Andy
James -

I pretty doubt about this - "c = line.count(k)" You might wanna
recheck on that.

I think it would be obvious how to write this:

for i,line in enumerate(linelist):
   line = line.split()
   for k in line:
 if keyword.iskeyword(k):
   c = line.count(k)
   total += line.count(k)
   print "Line #%d has %d keywords." % (i+1, c)
   break

print "Total keyords are: %d" % total


>
> I think it would be obvious how to write this:
>
> for i,line in enumerate(linelist):
>line = line.split()
>for k in line:
>  if keyword.iskeyword(k):
>c = line.count(k)
>total += line.count(k)
>print "Line #%d has %d keywords." % (i+1, c)
>break
>
> print "Total keyords are: %d" % total


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


Re: Counting

2007-05-06 Thread Andy
.o0

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


Examples / Links needed

2007-05-06 Thread Andy
Gurus, I'm looking for definite examples (pardon me if I'm not clear
here) on Stack class...Somewhat like this :

class Stack(object):
  def __init__(self__)
  self.__contents = []


and ad hoc implementation of a class based on number system like for
example somewhat like this


def __imult__(self, other):
   self.__numerator   *= other.__numerator
   self.__denominator *= other.__denominator
   .
   .
  return self



I'm not satisfied with Python Docs. Thanks in advance.

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


Development for dual core machine

2007-08-19 Thread Andy
Hi guys,

I'm sorry, I'm not sure this is the correct group to be asking this
kind of question...

I'm going to develop a software package that includes a web server
(and PHP code) , a database, and some Python code of course.  I am
being strongly suggested to make it to work on a dual- or multi-core
computer, but I'm confused on how to take advantage of the multiple
CPUs.

>From what I read, I think that simply by making the package run in
several separate processes (web server, database server, Python
interpreter, etc.), and/or using multiple threads (which I will
anyway) the package should be able to use multiple CPUs.

Is my understanding correct?  So actually, all I have to do is just
write my multi-threaded Python code as usual?  And how is it decided
which process and which threads go to CPU 1, CPU 2, etc.?  Perhaps the
BIOS?

Any advice greatly appreciated.
Andy

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


Re: Development for dual core machine

2007-08-19 Thread Andy
Thanks guys for the suggestions.

Andy

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


Re: stopping a while True: with the keyboard

2007-09-25 Thread Andy
Hi,

I think you can use the 'curses' module to catch the keyboard event.
The name of the method is 'keyname()'.  But I'm afraid curses is not
available on Windows Python, so you may have to be a bit more
imaginative.  I just tried with Python 2.4 on Windows XP.

To leave the while loop, use the 'break' command.

Andy

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


Embedded Python - Blocking Python Function

2007-11-14 Thread andy
I embed multiple interpreters. I create the interpreter and modules in
the primary thread of my application:

PyEval_AcquireLock();
thread = Py_NewInterpreter();
PyThreadState_Swap(thread);

...initialize modules, etc

PyThreadState_Swap(maininterpreter);
PyEval_ReleaseLock();

Then I create a C thread called "main" which calls a function called
"Main" in the Python interpreter:

PyEval_AcquireLock();
PyThreadState_Swap(thread);
moduledictionary = PyModule_GetDict(pmodule);
PyObject_CallObject(PyDict_GetItemString(moduledictionary, "Main"),
NULL);
PyThreadState_Swap(maininterpreter);
PyEval_ReleaseLock();

The problem is that the function "Main" in the Python script can take
up to 60 seconds to execute. How can I terminate this thread (and
therefore the Main function in python) cleanly from the primary thread
of my application?

If I try to call Py_EndInterpreter(thread); then I get a runtime error
(presumably because the Main function is still executing).

thanks, Andy

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


Re: Embedded Python - Blocking Python Function

2007-11-15 Thread andy
On Nov 14, 4:20 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> Not forcibly - you need some cooperation from the Main function. Maybe
> setting a global variable that Main checks periodically.

Thanks. I'll give that a try!

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


Re: Embedded Python - Blocking Python Function

2007-11-15 Thread andy
On Nov 15, 9:43 am, [EMAIL PROTECTED] wrote:
> On Nov 14, 4:20 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
> wrote:
>
> > Not forcibly - you need some cooperation from the Main function. Maybe
> > setting a global variable that Main checks periodically.
>
> Thanks. I'll give that a try!
>
> Andy

It works but the problem is that the script will be written by the end
user. If they make a mistake and the cancel flag isn't perodically
checked then it seems I have no way of cleanly ending the interpreter.
If I wait for a specific time after requesting the Main function stop
I need to be able to kill the interpreter without a runtime error. Any
ideas?

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


Redirecting sys.stdin

2007-11-15 Thread andy
Can anyone tell me what I am doing wrong with the following code? When
python 2.4 is embedded it crashes because of the assignment to stdin.

import sys;

class RedirectB:
  def readline(self):
return "bar";

sys.stdin = RedirectB();

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


Re: Redirecting sys.stdin

2007-11-15 Thread andy
On Nov 15, 4:09 pm, [EMAIL PROTECTED] wrote:
> Can anyone tell me what I am doing wrong with the following code? When
> python 2.4 is embedded it crashes because of the assignment to stdin.
>
> import sys;
>
> class RedirectB:
>   def readline(self):
> return "bar";
>
> sys.stdin = RedirectB();

Seems the interpreter didn't like me using one class to redirect
stdout and stderr and another class to redirect stdin. Sigh.

Andy

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


Re: Embedded Python - Blocking Python Function

2007-11-16 Thread andy
On Nov 15, 5:03 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Thu, 15 Nov 2007 16:18:45 -0300, <[EMAIL PROTECTED]> escribió:
>
> > On Nov 15, 9:43 am, [EMAIL PROTECTED] wrote:
> >> On Nov 14, 4:20 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
> >> wrote:
>
> >> > Not forcibly - you need some cooperation from the Main function. Maybe
> >> > setting a global variable that Main checks periodically.
>
> > It works but the problem is that the script will be written by the end
> > user. If they make a mistake and the cancel flag isn't perodically
> > checked then it seems I have no way of cleanly ending the interpreter.
> > If I wait for a specific time after requesting the Main function stop
> > I need to be able to kill the interpreter without a runtime error. Any
> > ideas?
>
> You could use PyThreadState_SetAsyncExc - it's supposed to raise an
> exception in another thread. There is a Cookbook recipe using it here
> <http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496960>
> I've never actually used it, but I want to try it some day, so please
> report back your findings if you decide to use this function.
>
> --
> Gabriel Genellina


It seems this is the function I need, however the following gave an
access violation:

PyEval_AcquireLock();
PyThreadState_Swap(thread);

// stop interpreter by sending system exit exception to it's thread
PyThreadState_SetAsyncExc(thread->thread_id, PyExc_SystemExit);

PyThreadState_Swap(maininterpreter);
PyEval_ReleaseLock();

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


Embedding Python - Passing by Reference

2007-11-29 Thread andy
I understand the parameters to Python functions are passed by
reference:

def foo(a):
  a = a + 1

Will change the value of a in the calling function. How do I implement
the equivalent in C when extending Python?

I know how to write a function that can be called from Python and I
know how to use PyArg_ParseTuple to get the value of a. But how do I
update the value of a in C? I tried (greatly simplified):

PyObject *a;
int value;
PyArg_ParseTuple(args, "O", &a);
value = PyLong_AsLong(a);
value++;
a = PyLong_FromLong(value);

but this doesn't work. Any suggestions?

Note that I am trying to wrap an existing C based API as closely as
possible, so I can't return the value using return (this example is
greatly simplified and I'm already using the return value for other
things).

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


Re: Embedding Python - Passing by Reference

2007-11-29 Thread andy
Thanks for the replies - I see that I completely misunderstood
"passing by reference" when discussing Python. It looks like wrapping
the object up in a list will be the path I go down as it remains
closer to the C API I am wrapping.

Thanks again!

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


Regression test test_site failed on current trunk

2009-02-19 Thread Andy
Hi,

I checked out the python trunk (curently 2.7a0), compiled it on my
linux machine and run the regression test suit. Below is the output of
the failed part:

test_site
[14871 refs]
test test_site failed -- Traceback (most recent call last):
  File "/mybook/storage/python_lnx/Lib/test/test_site.py", line 105,
in test_s_option
self.assertEqual(rc, 1)
AssertionError: 0 != 1

Is this something serious.

I compiled python with:
./configure --prefix=/dev/null --with-pydebug
make -s

Further I've got problems with moving the cursor when I started python
(2.7a0). There are only esc sequences displayed. My Local installation
(2.5.2) works fine.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Regression test test_site failed on current trunk

2009-02-19 Thread Andy
On 19 Feb., 21:47, Steve Holden  wrote:

> Do you mean you can't get previous lines in your Python command history
> to show up? This sounds as though you may not have built the readline
> support in to your experimental build. I can't remember exactly what the
> deal is, but I know that readline is GPL licensed, so it may not come as
> part of the standard distribution.

Thanks for your reply.
I just want to move left and right with the cursor keys.
Thats it.
I installed libreadline5-dev and rerun ./configure and make
...now it works.


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


Question related to wx and dynamically updating windows

2008-10-20 Thread Andy


I want to dynamically update a list of elements shown as a checkbox 
list. A file is used to store the elements, and elements can be added 
and deleted from the list. The trouble is that the window is not 
properly updated after deleting/adding items.


I use the Detach()/Destroy() to remove the sizer, and then I create a 
new and updated sizer again. Apparently, not in a correct way...



#File createleftpanel.py
import wx
from gettext import gettext as _
from project import Project


"""
The class createLeftPanel
"""

class createLeftPanel(wx.Panel):

def __init__(self, parent):
wx.Panel.__init__(self, parent)

#Initialization
self.SetBackgroundColour('White')
self.filename = 'tempfile.sim'

#Initiate file:
initList = ['alfa', 'bravo', 'ekko']
Project(self.filename).writeProject(initList)
readList = Project(self.filename).readProject()

#Boxes
self.mainbox = wx.BoxSizer(wx.VERTICAL)
self.aSavedSizer = self.MakeSavedSizer(readList)

#Adding everything to mainbox
self.mainbox.Add(self.aSavedSizer, 0, wx.RIGHT | wx.LEFT, 3)

self.mainbox.Fit(self)
self.SetSizer(self.mainbox)
self.Layout()

def OnDelete(self, event):
#Deleting element from file
for counter in range(0, len(self.elementList)):
if self.elementList[counter][0].GetValue() == True:
Project(self.filename).removeLineFromProject(\
self.elementList[counter][2])

#Detaching and destroying the previous savedSizer
self.mainbox.Detach(self.aSavedSizer)
self.aSavedSizer.Destroy()

#Adding new aSavedSizer from file
aSavedList = Project(self.filename).readProject()
self.aSavedSizer = self.MakeSavedSizer(aSavedList)
self.mainbox.Add(self.aSavedSizer, 0, wx.RIGHT | wx.LEFT, 3)
self.mainbox.Fit(self)
self.SetSizer(self.mainbox)
self.Layout()

def OnAdd(self, event):
#Adding element to file
Project(self.filename).appendLineToProject(self.addText.GetValue())

#Detaching and destroying the previous savedSizer
self.mainbox.Detach(self.aSavedSizer)
self.aSavedSizer.Destroy()

#Adding new aSavedSizer from file
aSavedList = Project(self.filename).readProject()
self.aSavedSizer = self.MakeSavedSizer(aSavedList)
self.mainbox.Add(self.aSavedSizer, 0, wx.RIGHT | wx.LEFT, 3)
self.mainbox.Fit(self)
self.SetSizer(self.mainbox)
self.Layout()


def MakeSavedSizer(self, savedList):

#Putting saved items into static box together with checkbox for 
deleting

savedBox = wx.StaticBox(self, -1, _('Saved words'))
savedSizer = wx.StaticBoxSizer(savedBox, wx.VERTICAL)

self.elementList = []
for item in savedList:
self.element = wx.CheckBox(self, -1, item, 
pos=wx.DefaultPosition, \

  size=wx.DefaultSize)
print item
self.elementList.append((self.element, 
self.element.GetId(), item))

savedSizer.Add(self.element, 0, wx.ALL, 5)

#Delete button
deleteBox = wx.BoxSizer(wx.HORIZONTAL)
deleteText = wx.StaticText(self, -1, '', size=(125,-1))
deleteButton = wx.Button(self, -1, _('Delete'))
deleteBox.Add(deleteText, 0, wx.ALL, 1)
deleteBox.Add(deleteButton, 0, wx.ALL, 1)
self.Bind(wx.EVT_BUTTON, self.OnDelete, deleteButton)

#Add element + button
addBox = wx.BoxSizer(wx.HORIZONTAL)
self.addText = wx.TextCtrl(self, -1, value=_(''),  size = (125, 
-1), \

 validator=wx.DefaultValidator)
self.addText.SetMaxLength(12)

addButton = wx.Button(self, -1, _('Add'))
addBox.Add(self.addText, 0, wx.ALL, 1)
addBox.Add(addButton, 0, wx.ALL, 1)
self.Bind(wx.EVT_BUTTON, self.OnAdd, addButton)


#Add to savedSizer
savedSizer.Add(deleteBox, 0, wx.EXPAND, 0)
savedSizer.Add(addBox, 0, wx.EXPAND, 0)

#self.SetSizer(savedSizer)
self.Fit()

return savedSizer


""" Testing routines for testing this module only"""
class Frame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent=None, id=-1)
self.panel = createLeftPanel(self)
self.statusbar = self.CreateStatusBar()

class App(wx.App):
def OnInit(self):
wx.App.__init__(self)
self.frame = Frame(-1)
self.frame.Show()
self.SetTopWindow(self.frame)
return True

def OnExit(self):
pass

if __name__ == '__main__':
app = App()
app.MainLoop()



#File project.py
import os

"""
The Project class handles reading/writing strings from/to file
"""

class Project(object):
def __init__(se

2.6, 3.0, and truly independent intepreters

2008-10-22 Thread Andy
threaded use?  The
assumption here is that caller ensures safety (e.g. ensuring that
neither interpreter is in use when serializing data from one to
another).

I believe that true python independent thread/interpreter support is
paramount and should become the top priority because this is the key
consideration used by developers when they're deciding which
interpreter to embed in their app. Until there's a hello world that
demonstrates running independent python interpreters on multiple app
threads, lua will remain the clear choice over python.  Python 3 needs
true interpreter independence and multi-threaded support!


Thanks,
Andy O'Meara


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


Re: 2.6, 3.0, and truly independent intepreters

2008-10-22 Thread Andy

Hi Thomas -

I appreciate your thoughts and time on this subject.

>
> The result is that separate COM objects implemented as Python modules and
> converted into separate dlls by py2exe do not share their interpreters even
> if they are running in the same process.  Of course this only works on 
> windows.
> In effect this is similar to using /statically/ linked python interpreters
> in separate dlls.  Can't you do something like that?

You're definitely correct that homebrew loading and linking would do
the trick.  However, because our python stuff makes callbacks into our
C/C++, that complicates the linking process (if I understand you
correctly).  Also, then there's the problem of OS X.


> > - In python 3, the C module API now supports true interpreter
> > independence, but have all the modules in the python codebase been
> > converted over?  Are they all now truly compliant?  It will only take
> > a single static/global state variable in a module to potentially cause
> > no end of pain in a multiple interpreter environment!  Yikes!
>
> I don't think this is the case (currently).  But you could submit patches
> to Python so that at least the 'official' modules (builtin and extensions)
> would behave corectly in the case of multiple interpreters.  At least
> this is a much lighter task than writing your own GIL-less interpreter.
>

I agree -- and I've been considering that (or rather, having our
company hire/pay part of the python dev community to do the work).  To
consider that, the question becomes, how many modules are we talking
about do you think?  10? 100?  I confess that I'm no familiar enough
with the full C python suite to have a good idea of how much work
we're talking about here.

Regards,
Andy




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


Re: 2.6, 3.0, and truly independent intepreters

2008-10-22 Thread Andy


> > - In python 3, the C module API now supports true interpreter
> > independence, but have all the modules in the python codebase been
> > converted over?
>
> No, none of them.

:^)

>
> > - How close is python 3 really to true multithreaded use?
>
> Python is as thread-safe as ever (i.e. completely thread-safe).
>

If you're referring to the fact that the GIL does that, then you're
certainly correct.  But if you've got multiple CPUs/cores and actually
want to use them, that GIL means you might as well forget about them.
So please take my use of "true multithreaded" to mean "turning off"
the GIL and push the responsibility of object safety to the client/API
level (such as in my QuickTime API example).


> > I believe that true python independent thread/interpreter support is
> > paramount and should become the top priority because this is the key
> > consideration used by developers when they're deciding which
> > interpreter to embed in their app. Until there's a hello world that
> > demonstrates running independent python interpreters on multiple app
> > threads, lua will remain the clear choice over python.  Python 3 needs
> > true interpreter independence and multi-threaded support!
>
> So what patches to achieve that goal have you contributed so far?
>
> In open source, pleas have nearly zero effect; code contributions is
> what has effect.
>

This is just my second email, please be a little patient. :^)  But
more seriously, I do represent a company ready, able, and willing to
fund the development of features that we're looking for, so please
understand that I'm definitely not coming to the table empty-handed
here.


> I don't think any of the current committers has a significant interest
> in supporting multiple interpreters (and I say that as the one who wrote
> and implemented PEP 3121). To make a significant change, you need to
> start with a PEP, offer to implement it once accepted, and offer to
> maintain the feature for five years.
>

Nice to meet you! :^) Seriously though, thank you for all your work on
3121 and taking the initiative with it!  It's definitely the first
step in what companies like ours attract us to embedded an interpreted
language.  Specifically: unrestricted interpreter and thread-
independent use.

I would *love* for our company to be 10 times larger and be able to
add another zero to what we'd be able to hire/offer the python dev
community for work that we're looking for, but we unfortunately have
limits at the moment. And I would love to see python become the
leading choice when companies look to use an embedded interpreter, and
I offer my comments here to paint a picture of what can make python
more appealing to commercial software developers.  Hopefully, the
python dev community doesn't underestimate the dev funding that could
potentially come in from companies if python grew in certain ways!

So, that said, I represent a company willing to fund the development
of features that move python towards thread-independent operation.  No
software engineer can deny that we're entering a new era of
multithreaded processing where support frameworks (such as python)
need to be open minded with how they're used in a multi-threaded
environment--that's all I'm saying here.

Anyway, I can definitely tell you and anyone else interested that
we're willing to put our money where our wish-list is.  As I mentioned
in my previous post to Thomas, the next step is to get an
understanding of the options available that will satisfy our needs.
We have a budget for this, but it's not astronomical (it's driven by
the cost associated with dropping python and going with lua--or,
making our own pared-down interpreter implementation).  Please let me
be clear--I love python (as a language) and I don't want to switch.
BUT, we have to be able to run interpreters in different threads (and
get unhindered/full CPU core performance--ie. no GIL).

Thoughts? Also, please feel free to email me off-list if you prefer.

Oh, while I'm at it, if anyone in the python dev community (or anyone
that has put real work into python) is interested in our software,
email me and I'll hook you up with a complimentary copy of the
products that use python (music visuals for iTunes and WMP).

Regards,
Andy




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


Re: 2.6, 3.0, and truly independent intepreters

2008-10-22 Thread Andy

>
> What you describe, truly independent interpreters, is not threading at
> all: it is processes, emulated at the application level, with all the
> memory cost and none of the OS protections.  True threading would
> involve sharing most objects.
>
> Your solution depends on what you need:
> * Killable "threads" -> OS processes
> * multicore usage (GIL removal) -> OS processes or alternative Python
> implementations (PyPy/Jython/IronPython)
> * Sane shared objects -> safethread


I realize what you're saying, but it's better said there's two issues
at hand:

1) Independent interpreters (this is the easier one--and solved, in
principle anyway, by PEP 3121, by Martin v. Löwis, but is FAR from
being carried through in modules as he pointed out).  As you point
out, this doesn't directly relate to multi-threading BUT it is
intimately tied to the issue because if, in principle, every module
used instance data (rather than static data), then python would be
WELL on its way to "free threading" (as Jesse Noller calls it), or as
I was calling it "true multi-threading".

2) Barriers to "free threading".  As Jesse describes, this is simply
just the GIL being in place, but of course it's there for a reason.
It's there because (1) doesn't hold and there was never any specs/
guidance put forward about what should and shouldn't be done in multi-
threaded apps (see my QuickTime API example).  Perhaps if we could go
back in time, we would not put the GIL in place, strict guidelines
regarding multithreaded use would have been established, and PEP 3121
would have been mandatory for C modules.  Then again--screw that, if I
could go back in time, I'd just go for the lottery tickets!! :^)

Anyway, I've been at this issue for quite a while now (we're
approaching our 3rd release cycle), so I'm pretty comfortable with the
principles at hand.  I'd say the theme of your comments share the
theme of others here, so perhaps consider where end-user software
houses (like us) are coming from.  Specifically, developing commercial
software for end users imposes some restrictions that open source
development communities aren't often as sensitive to, namely:

- Performance -- emulation is a no-go (e.g. Jython)
- Maturity and Licensing -- experimental/academic projects are no-go
(PyPy)
- Cross platform support -- love it or hate it, Win32 and OS X are all
that matter when you're talking about selling (and supporting)
software to the masses.  I'm just the messenger here (ie. this is NOT
flamebait).  We publish for OS X, so IronPython is therefore out.

Basically, our company is at a crossroads where we really need light,
clean "free threading" as Jesse calls it (e.g. on the iPhone, using
our python drawing wrapper to do primary drawing while running python
jobs on another thread doing image decoding and processing).  In our
current iPhone app, we achieve this by using two python bundles
(dynamic libs) in the way I described in my initial post.  Sure, thus
solves our problem, but it's pretty messy, sucks up resources, and has
been a pain to maintain.

Moving forward, please understand my posts here are also intended to
give the CPython dev community a glimpse of the issues that may not be
as visible to you guys (as they are for dev houses like us).  For
example, it'd be pretty cool if Blizzard went with python instead of
lua, wouldn't you think?  But some of the issues I've raised here no
doubt factor in to why end-user dev houses ultimately may have to pass
up python in favor of another interpreted language.

Bottom line: why give prospective devs any reason to turn down python--
there's just so many great things about python!

Regards,
Andy






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


Re: 2.6, 3.0, and truly independent intepreters

2008-10-22 Thread Andy
Jesse, Terry, Martin -

First off, thanks again for your time and interest in this matter.
It's definitely encouraging to know that time and real effort is being
put into the matter and I hope my posts on this subject are hopefully
an informative data point for everyone here.

Thanks for that link to Adam Olsen's work, Jesse--I'll definitely look
more closely at it.  As I mentioned in my previous post, end-user devs
like me are programmed to get nervous around new mods but at first
glance there definitely seems to be interesting.  My initial reaction,
as interesting as the project is, goes back to by previous post about
putting all the object safety responsibility on the shoulders of the
API client.  That way, one gets the best of both worlds: free
threading and no unnecessary object locking/blocking (ie. the API
client will manage moving the synchronization req'd to move objects
from one interpreter to another).  I could have it wrong, but it seems
like safethread inserts some thread-safety features but they come at
the cost of performance. I know I keep mentioning it, but I think the
QuickTime API (and its documentation) is a great model for how any API
should approach threading.  Check out their docs to see how they
address it; conceptually speaking, there's not a single line of thread
safety in QuickTime:

http://developer.apple.com/technotes/tn/tn2125.html

In short: multiple thread is tricky; it's the responsibility of the
API client to not do hazardous things.

And for the record: the module multiprocessing is totally great answer
for python-level MP stuff--very nice work, Jesse!

I'd like to post and discuss more, but I'll pick it up tomorrow...
All this stuff is fun and interesting to talk about, but I have to get
to some other things and it unfortunately comes down to cost
analysis.  Sadly, I look at it as I can allocate 2-3 man months (~
$40k) to build our own basic python interpreter implementation that
solves our need for free threading and increased performance (we've
built various internal interpreters over the years so we have good
experience in house, our tools are high performance, and we only use a
pretty small subset of python).  Or, there's the more attractive
approach to work with the python dev community and put that dev
expenditure into a form everyone can benefit from.


Regards,
Andy




On Oct 22, 5:21 pm, "Jesse Noller" <[EMAIL PROTECTED]> wrote:
> On Wed, Oct 22, 2008 at 12:32 PM, Andy <[EMAIL PROTECTED]> wrote:
> > And, yes, I'm aware of the multiprocessing module added in 2.6, but
> > that stuff isn't lightweight and isn't suitable at all for many
> > environments (including ours).  The bottom line is that if you want to
> > perform independent processing (in python) on different threads, using
> > the machine's multiple cores to the fullest, then you're out of luck
> > under python 2.
>
> So, as the guy-on-the-hook for multiprocessing, I'd like to know what
> you might suggest for it to make it more apt for your - and other
> environments.
>
> Additionally, have you looked 
> at:https://launchpad.net/python-safethreadhttp://code.google.com/p/python-safethread/w/list
> (By Adam olsen)
>
> -jesse

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


Re: 2.6, 3.0, and truly independent intepreters

2008-10-22 Thread Andy


> You seem confused.  PEP 3121 is for isolated interpreters (ie emulated
> processes), not threading.

Please reread my points--inherently isolated interpreters (ie. the top
level object) are indirectly linked to thread independence.  I don't
want to argue, but you seem hell-bent on not hearing what I'm trying
to say here.

>
> Got some real benchmarks to back that up?  How about testing it on a
> 16 core (or more) box and seeing how it scales?
>

I don't care to argue with you, and you'll have to take it on faith
that I'm not spouting hot air.  But just to put this to rest, I'll
make it clear in this Jython case:

You can't sell software to end users and expect them have a recent,
working java distro.  Look around you: no real commercial software
title that sells to soccer moms and gamers use java.  There's method
to commercial software production, so please don't presume that you
know my job, product line, and customers better than me, ok?

Just to put things in perspective, I already have exposed my company
to more support and design liability than I knew I was getting into by
going with python (as a result of all this thread safety and
interpreter independence business).  I love to go into that one, but
it's frankly just not a good use of my time right now.  Please just
accept that when someone says an option is a deal breaker, then it's a
deal breaker.  This isn't some dude's masters thesis project here--we
pay our RENT and put our KIDS through school because we sell and ship
software that works is meant to entertain people happy.

>
> I'd like to see python used more, but fixing these things properly is
> not as easy as believed.  Those in the user community see only their
> immediate problem (threads don't use multicore).  People like me see
> much bigger problems.  We need consensus on the problems, and how to
> solve it, and a commitment to invest what's required.

Well, you seem to come down pretty hard on people that at your
doorstep saying their WILLING and INTERESTED in supporting python
development.  And, you're exactly right:  users see only their
immediate problem--but that's the definition of being a user.  If
users saw the whole picture from the dev side, then they be
developers, not users.

Please consider that you're representing the python dev community
here; I'm you're friend here, not your enemy.

Andy




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


How Do I think of import?

2009-04-05 Thread Andy
Hi: 

Sorry for the detail of this question but I hope its useful to others as 
well as myself. 
I'm planning to do a Python wrapper for an existing GUI environment that 
is not one of the standard environments. So I have complete freedom. Ive 
done various smaller things in Python with some success. But this is 
large enough to need proper planning.

The current environment is C but with a C++ structure. Widgets are 
developed from simpler widgets, PtBasic -> PtLabel-> PtButton etc. Each 
widget has its own C header that defines widget parameters, callback 
options various functions. Each header includes the header defining the 
next level down. I plan to extract parameters, bit masks callbacks etc 
using a modified h2py, so I have all I need at my fingertips. But how do 
I organise it? What structure do I impose on my import files? 

The options seem to be:
a) copy the C headers structure!
"from photon.PtButton import *" photon.PtButton imports Its own 
definitions and imports photon.PtLabel which imports PtBasic etc.
This is a simple structure. However- all users will import 
multiple widgets and I see a lot of wasted effort by Python trying to  
import PtBasic and other modules multiple times. 

b) Create modules by their function! 
photon.defititions, photon.callbacks  and photon.functions
then maybe a breakdown under definitions for example. 
photon.definitions.PtButton

c) Just give up trying to be efficient and assume that the user will 
want to access all definitons etc.  Simply create a photon.all and let 
that be imported. 'from photon.all import *" 

No matter what path I consider, I see a very crowded namespace. Is this 
inevitable? Should I just get on with the wrapper and not worry ? 

Sizing.. Currently PtBasic has 90 definitions PtLabel 54 and PtButton 
11. 

Thanks,
Andy




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


Re: Please, I Have A Question before I get started

2006-03-15 Thread Andy
I've knocked together something which may help you to get started. It may
not be the best solution to your problem, but it's based on some code that I
had lying around and it should be easy for you to customise.

It uses a cherrypy server with a web ui. Send me a note with your address
and I'll forward the code on to you (34 KB).

[EMAIL PROTECTED]

Andy


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


Re: remove a directory with special chars

2006-03-18 Thread andy
Is there a special reason you want to use Python to do this?  The Linux
command shell would probably do exactly the same job (you can specify
backslash-escaped characters at the command-line)...

anyway to do it in python:

  import os
  os.remove("/path/to/the/file/.\177\177")

Note that under Linux, hidden files start with a "." - that's what makes
them hidden.

By the way, "\177" (decimal 79) is a letter "O"... I suspect you meant
"\011" (decimal 9) which is backspace...

Hope that helps,
-andyj

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


Re: Can I use a conditional in a variable declaration?

2006-03-19 Thread andy
[EMAIL PROTECTED] wrote:

>I've done this in Scheme, but I'm not sure I can in Python.
>
>I want the equivalent of this:
>
>if a == "yes":
>   answer = "go ahead"
>else:
>   answer = "stop"
>
>in this more compact form:
>
>
>a = (if a == "yes": "go ahead": "stop")
>
>
>is there such a form in Python? I tried playing around with lambda
>expressions, but I couldn't quite get it to work right.
>
>  
>
How about:

a = ["stop","go ahead"][a == "yes"]

This works because:

>>> int("yes" == "yes")
1
>>> int("yes" == "no")
0

Taking into account all the previous comments - both the literal list
elements are evaluated; there is no short-cirtuiting here. If they're
just literals, it's no problem, but if they're (possibly
compute-intensive) function calls, it would matter. I find the list
evaluation easier to parse than the and/or equation, and in instances
where that would be necessary, I will use the longhand if ... else ...
structure for readability.

hth,
-andy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyserial script doesnt execute properly

2010-03-09 Thread Andy
Hi Kishore,

Have you tried "ser=serial.Serial(port='COM2', baudrate=9600)" instead
of "port='\\.\COM2'"?

Also, I'd suggest you temporarily define some other parameters that
now you're leaving to default values.  From the documentation of
pyserial:
readline(size=None, eol='\n')

You're sure that your Arduino device is sending a '\n' right after the
'1', aren't you?  Or is it two consecutive '1'?

And another idea:  If this is your first experience with PySerial, I
suggest you first use some free software as counterpart to your
Arduino device in order to confirm the microcontroller is sending
exactly what you think it is sending.  In other words, is it sending
to your Python program '11' or '1\n1\n'?  Also to confirm other
details such as parity bits, baud, etc.

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


Can 32-bit and 64-bit Python coexist in the same computer?

2010-10-26 Thread Andy
Hi guys!

I got a new laptop computer which came with the 64-bit version of
Windows 7.  I installed the 64-bit versions of Python and a few other
libraries and wrote a few Python programs right there.  If I copy the
Python scripts to a 32-bit computer, it runs flawlessly.  But in the
future I may still need to distribute my compiled programs to people
who use 32-bit Windows and it seems that neither PyInstaller nor
py2exe can cross compile a 32-bit application from this 64-bit
computer.

So ugly as it sounds, I'm considering installing in parallel the 32-
bit version of Python on this same computer.  Is there anything I need
to know or a better way to achieve this instead of having a double
Python installation?

By the way, I use Python 2.6, so it would be [Python 2.6.x 32-bit] and
[Python 2.6.x 64-bit] on the same computer.

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


Python Regular Expressions

2011-06-22 Thread Andy Barnes
Hi,

I am hoping someone here can help me with a problem I'd like to
resolve with Python. I have used it before for some other projects but
have never needed to use Regular Expressions before. It's quite
possible I am following completley the wrong tack for this task (so
any advice appreciated).

I have a source file in csv format that follows certain rules. I
basically want to parse the source file and spit out a second file
built from some rules and the content of the first file.

Source File Format:

Name, Type, Create, Study, Read, Teach, Prerequisite
# column headers

Distil Mana, Lore, n/a, 70, 38, 21
Theurgic Lore, Lore, n/a, 105, 70, 30, Distil Mana
Talismantic Lore, Lore, n/a, 150, 100, 50
Advanced Talismantic Lore, Lore, n/a, 100, 60, 30, Talismantic Lore,
Theurgic Lore

The input file I have has over 700 unique entries. I have tried to
cover the four main exceptions above. Before I detail them - this is
what I would like the above input file, to be output as (dot
diagramming language incase anyone recognises it):

Name, Type, Create, Study, Read, Teach, Prerequisite
# column headers

DistilMana [label="{ Distil Mana |{Type|7}|{70|38|21}}"];
TheurgicLore [label="{ Theurgic Lore |{Lore|n/a}|{105|70|30}}"];
DistilMana -> TheurgicLore;
TalismanticLore [label="{ Talismantic Lore |{Lore|n/a}|{150|100|
50}}"];
AdvanvedTalismanticLore [label="{ Advanced Talismantic Lore |{Lore|n/
a}|{100|60|30}}"];
TalismanticLore -> AdvanvedTalismanticLore;
TheurgicLore -> AdvanvedTalismanticLore;

It's quite a complicated find and replace operation that can be broken
down into some easy stages. The main thing the sample above showed was
that some of the entries won't list any prerequisits - these only need
the descriptor entry creating. Some of them have more than one
prerequisite. A line is needed for each prerequisite listed, linking
it to it's parent.

You can also see that the 'name' needs to have spaces removed and it's
repeated a few times in the process. I Hope it's easy to see what I am
trying to achieve from the above. I'd be very happy to accept
assistance in automating the conversion of my ever expanding csv file,
into the dot format described above.

Andy

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


Re: Python Regular Expressions

2011-06-22 Thread Andy Barnes
to expand. I have parsed one of the lines manually to try and break
the process I'm trying to automate down.

source:
Theurgic Lore, Lore, n/a, 105, 70, 30, Distil Mana

output:
TheurgicLore [label="{ Theurgic Lore |{Lore|n/a}|{105|70|30}}"];
DistilMana -> TheurgicLore;

This is the steps I would take to do this conversion manually:

1) Take everything prior to the first comma and remove all the spaces,
insert it into a newline:

TheurgicLore

2) append the following string ' [label="{ '

TheurgicLore [label="{

3) append everything prior to the first comma (this time we don't need
to remove the spaces)

TheurgicLore [label="{ Theurgic Lore

4) append the following string ' |{'

TheurgicLore [label="{ Theurgic Lore |{

5) append everything between the 1st and 2nd comma of the source file
followed by a '|'

TheurgicLore [label="{ Theurgic Lore |{Lore|

6) append everything between the 2nd and 3rd comma of the source file
followed by a '}|{'

TheurgicLore [label="{ Theurgic Lore |{Lore|n/a}|{

7) append everything between the 3rd and 4th comma of the source file
followed by a '|'

TheurgicLore [label="{ Theurgic Lore |{Lore|n/a}|{105|

8) append everything between the 4th and 5th comma of the source file
followed by a '|'

TheurgicLore [label="{ Theurgic Lore |{Lore|n/a}|{105|70|

9) append everything between the 5th and 6th comma of the source file
followed by a '}}"];'

TheurgicLore [label="{ Theurgic Lore |{Lore|n/a}|{105|70|30}}"];

Those 9 steps spit out my fist line of output file as above
"TheurgicLore [label="{ Theurgic Lore |{Lore|n/a}|{105|70|30}}"];" I
now have to parse the dependancies onto a newline.

# this next process needs to be repeated for each prerequisite, so if
there are two pre-requisites it would need to keep parsing for more
comma's.
1a) take everything between the 6th and 7th comma and put it at the
start of a new line (remove spaces)

DistilMana

2a) append '-> '

DistilMana ->

3a) append everything prior to the first comma, with spaces removed

DistilMana -> TheurgicLore

This should now be all the steps to spit out:

TheurgicLore [label="{ Theurgic Lore |{Lore|n/a}|{105|70|30}}"];
DistilMana -> TheurgicLore;
-- 
http://mail.python.org/mailman/listinfo/python-list


threads with gtk gui problem

2011-05-14 Thread Andy Baxter

Hi,

I'm working on adding a Gtk GUI to a python program. Its main function 
is to read raw data from an arduino board over USB, and convert it to 
MIDI note/controller events to be sent to another program. I've had it 
working fine with just a command line interface, but when I replaced the 
command line with a Gtk interface, I started having problems getting the 
thread that reads the USB port to run.


I'm not sure what the custom is on this list for pasting code - It's a 
long program so I don't want to paste the whole thing.


The sequence of events I've coded is:

- the program starts.
- the port reader thread (which is a threading.Thread subclass) is 
initialised.
- the object which controls the interface is initialised (i.e. the glade 
file is loaded.)
- the port reader is started (i.e. the 'start' method is called, which 
calls the 'run' method in a thread).

- then the gtk main loop is run.

The behaviour I'm getting is that the port reader either fails to start, 
or stops running at the point where it tries to initialise the serial 
port. It then does nothing until I close the main window, at which point 
it starts running again.


The port reader's run method begins like this:

   # the method called by the thread superclass to run the main loop of 
the thread.

   def run(self):
  # main loop of thread.
  print "Starting port reader."
  fhan=serial.Serial(port=keeper.config['usbPort'], 
baudrate=keeper.config['usbBaud'], timeout=0.1)

  print "1"
  fhan.open()
  print "2"
  seq=PySeq() # the sequencer library object
  port=seq.createOutPort(keeper.config['midiPortName']) # make a 
midi out port.

  midich=keeper.config['midich']
  print "3"
  while True:
 inbuf=[]
 print ".",
 char=fhan.read(1)
 if self.quit:
fhan.close()
return
 if len(char)==0: continue
 ... (code to process the character read in)

('keeper' is a global object which stores the config data and references 
to a few key objects).


When you start the program, the thread stops either before the first 
print statement, or on the line which initialises the serial port ( 
fhan=serial.Serial(...) ). '1', '2', and '3' only get printed /after/ 
you close the gtk main window.


Can anyone help with this?

cheers,

andy baxter



--

http://highfellow.org

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


Re: threads with gtk gui problem

2011-05-14 Thread andy baxter

On 14/05/11 14:12, Andy Baxter wrote:

Hi,

I'm working on adding a Gtk GUI to a python program. Its main function 
is to read raw data from an arduino board over USB, and convert it to 
MIDI note/controller events to be sent to another program. I've had it 
working fine with just a command line interface, but when I replaced 
the command line with a Gtk interface, I started having problems 
getting the thread that reads the USB port to run.


I've solved this by adding 'import gobject' and 'gobject.threads_init()' 
to the start of the program. Looks like if you don't do this then the 
gtk main loop never releases the python threading lock to other threads.


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


Re: threads with gtk gui problem

2011-05-14 Thread andy baxter

On 14/05/11 14:12, Andy Baxter wrote:

Hi,

I'm working on adding a Gtk GUI to a python program. Its main function 
is to read raw data from an arduino board over USB, and convert it to 
MIDI note/controller events to be sent to another program. I've had it 
working fine with just a command line interface, but when I replaced 
the command line with a Gtk interface, I started having problems 
getting the thread that reads the USB port to run.


I'm not sure what the custom is on this list for pasting code - It's a 
long program so I don't want to paste the whole thing.


The sequence of events I've coded is:

- the program starts.
- the port reader thread (which is a threading.Thread subclass) is 
initialised.
- the object which controls the interface is initialised (i.e. the 
glade file is loaded.)
- the port reader is started (i.e. the 'start' method is called, which 
calls the 'run' method in a thread).

- then the gtk main loop is run.

The behaviour I'm getting is that the port reader either fails to 
start, or stops running at the point where it tries to initialise the 
serial port. It then does nothing until I close the main window, at 
which point it starts running again.


The port reader's run method begins like this:

   # the method called by the thread superclass to run the main loop 
of the thread.

   def run(self):
  # main loop of thread.
  print "Starting port reader."
  fhan=serial.Serial(port=keeper.config['usbPort'], 
baudrate=keeper.config['usbBaud'], timeout=0.1)

  print "1"
  fhan.open()
  print "2"
  seq=PySeq() # the sequencer library object
  port=seq.createOutPort(keeper.config['midiPortName']) # make a 
midi out port.

  midich=keeper.config['midich']
  print "3"
  while True:
 inbuf=[]
 print ".",
 char=fhan.read(1)
 if self.quit:
fhan.close()
return
 if len(char)==0: continue
 ... (code to process the character read in)

('keeper' is a global object which stores the config data and 
references to a few key objects).


When you start the program, the thread stops either before the first 
print statement, or on the line which initialises the serial port ( 
fhan=serial.Serial(...) ). '1', '2', and '3' only get printed /after/ 
you close the gtk main window.




I've verified that the problem is due to the gtk main loop interfering 
with the thread I've started. If I use this code:


if __name__ == "__main__":
   print "Starting mapper"
   keeper=Keeper() # initialise the keeper. (A global object which 
holds references to key objects)

   keeper.start() # tell the keeper to start the port reader.
   for n in xrange(10): # wait for 10 seconds.
  time.sleep(1)
  print "x"
   #gtk.main() # start the gtk main loop.
   keeper.stop() # tell the keeper to shut things down.

the program runs correctly. I.e. values are read from the usb port when 
they come in.


if I use this code:

if __name__ == "__main__":
   print "Starting mapper"
   keeper=Keeper() # initialise the keeper. (A global object which 
holds references to key objects)

   keeper.start() # tell the keeper to start the port reader.
   #for n in xrange(10):
   #   time.sleep(1)
   #   print "x"
   gtk.main() # start the gtk main loop.
   keeper.stop() # tell the keeper to shut things down.

The port reader thread blocks at the point it tries to open the serial 
port. I.e. 'Starting port reader' is printed straight away, but '1', 
'2', and '3'  are only printed after you close the gtk main window.


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


Re: regular expression i'm going crazy

2011-05-16 Thread andy baxter

On 16/05/11 17:25, Tracubik wrote:

pls help me fixing this:

import re
s = "linka la baba"
re_s = re.compile(r'(link|l)a' , re.IGNORECASE)

print re_s.findall(s)

output:
['link', 'l']

why?
i want my re_s to find linka and la, he just find link and l and forget
about the ending a.


The round brackets define a 'capturing group'. I.e. when you do findall 
it returns those elements in the string that match what's inside the 
brackets. If you want to get linka and la, you need something like this:


>>> re_s = re.compile(r'((link|l)a)' , re.IGNORECASE)
>>> print re_s.findall(s)
[('linka', 'link'), ('la', 'l')]

Then just look at the first element in each of the tuples in the array 
(which matches the outside set of brackets).


see:
http://www.regular-expressions.info/python.html
--
http://mail.python.org/mailman/listinfo/python-list


indirect assignment question

2011-05-16 Thread Andy Baxter

Hi,

I have some lines of code which currently look like this:

  self.window = self.wTree.get_widget("mainWindow")
  self.outputToggleMenu = self.wTree.get_widget("menuitem_output_on")
  self.outputToggleButton = 
self.wTree.get_widget("button_toggle_output")

  self.logView = self.wTree.get_widget("textview_log")
  self.logScrollWindow = self.wTree.get_widget("scrolledwindow_log")

and I would like (for tidiness / compactness's sake) to replace them 
with something like this:

widgetDic = {
   "mainWindow": self.window,
   "menuitem_output_on": self.outputToggleMenu,
   "button_toggle_output": self.outputToggleButton,
   "textview_log": self.logView,
   "scrolledwindow_log": self.logScrollWindow
}
for key in widgetDic:
   ... set the variable in dic[key] to point to 
self.wTree.get_widget(key) somehow


what I need is some kind of indirect assignment where I can assign to a 
variable whose name is referenced in a dictionary value.


Is there a way of doing this in python?

thanks,

andy baxter

--

http://highfellow.org

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


Re: Cartoonify Myself

2011-05-17 Thread andy baxter

On 17/05/11 20:26, Chris M. Bartos wrote:

Hi,

Is there a Python module that can "cartoonify" a picture of myself? 
There's got to be an algorithm out there somewhere, right? If there is 
a way to cartoon a single picture, could you cartoonify a video, too?


Thanks for your help.


Chris



You could have a look at the python automation module for the gimp (a 
free software image editor). See e.g.:


http://starryalley.homelinux.net/blog/index.php?/archives/1248-Star-Trail-Automation-script-using-python-gimp.html
--
http://mail.python.org/mailman/listinfo/python-list


The split() function of Python's built-in module has changed in a puzzling way - is this a bug?

2021-04-22 Thread Andy AO
Upgrading from Python 3.6.8 to Python 3.9.0 and executing unit tests
revealed a significant change in the behavior of re.split().

but looking at the relevant documentation — Changelog  and re - Regular expression
operations - Python 3.9.4 documentation

yet no change is found.

number = '123'def test_Asterisk_quantifier_with_capture_group(self):
resultList = re.split(r'(\d*)', self.number)
if platform.python_version() == '3.6.8':
self.assertEqual(resultList,['', '123', ''])

else:
self.assertEqual(resultList,['', '123', '', '', ''])

I feel that this is clearly not in line with the description of the
function in the split documentation, and it is also strange that after
replacing * with +, the behavior is still the same as in 3.6.8.

   1. why is this change not in the documentation? Is it because I didn’t
   find it?
   2. Why did the behavior change this way? Was a bug introduced, or was it
   a bug fix?
-- 
https://mail.python.org/mailman/listinfo/python-list


PEP 572 implementation for Python

2018-07-22 Thread Andy Valencia
Hi, just an FYI (and request for comments).

I've coded up PEP 572 on top of "Tauthon" (sometimes in early
days known as "Python 2.8"):

https://github.com/vandys/tauthon (branch pep572)

After reading the PEP, Guido's comments, and looking at the code,
I realized that := just wants to be an augmented assignment
operator, and that what's really needed is to make all the augmented
assignment operators be expressions.

I also made them all *just* expressions, with higher precedence than
comma, but lower than the rest.  Also right associative, so:

a := b := c := 1

does what you expect without any special "multi assignment" code,
but just because expressions with right association do the right
thing anyway.

As augmented assignments are now just expressions, you can do:

while buf := ob.read():
...

but also:

if (self.count += 1) > PROBLEM:
...

In the interests of orthogonality, I did *not* add code to disable
places where some expressions--but not these new ones--could be used.
Go ahead and say:

a := 1

at the top level if that's what floats your boat.

Regards,
Andy Valencia
-- 
https://mail.python.org/mailman/listinfo/python-list


pdb which handles threads

2018-11-19 Thread Andy Valencia
I had yet another program where I accidentally had more than one
thread enter pdb at once, leaving me with the "pdb's battling for
the keyboard" syndrome.  So I extended pdb to recognize and handle
threads.  I added:

"jobs"

List threads, with one current one being the only one involved
with the keyboard.  All others wait politely.

"fg "

To switch to a different thread.

I welcome comments (it's for Python 2), under:

http://sources.vsta.org/

Regards,
Andy Valencia
-- 
https://mail.python.org/mailman/listinfo/python-list


TurboGears /.-ed, >new == True< or >new == "True"

2005-10-11 Thread Andy Leszczynski
watch this:
http://www.turbogears.org.nyud.net:8090/docs/wiki20/20MinuteWiki.mov

or read this:
http://www.turbogears.org.nyud.net:8090/docs/wiki2 0/page4.html

should not it be:

2 def save(self, pagename, data, submit, new):
3 hub.begin()
4 if new == True:
5 page = Page(pagename=pagename, data=data)
6 else:
7 page = Page.byPagename(pagename)
8 page.data = data

instead of:

4 if new == "True":
-- 
http://mail.python.org/mailman/listinfo/python-list


piping out binaries properly

2005-10-11 Thread Andy Leszczynski
I have got following program:

import sys
import binascii
from string import *
sys.stdout.write(binascii.unhexlify("41410A4141"))


when I run under Unix I got:

$ python u.py > u.bin
$ od -t x1 u.bin
000 41 41 0a 41 41

and under Windows/Cygwin following:

$ python u.py > u.bin
$ od -t x1 u.bin
000 41 41 0d 0a 41 41
006


The question is how can I pipe out binary content properly and platform
independently?


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


Re: piping out binaries properly

2005-10-11 Thread Andy Leszczynski
Mike Meyer wrote:
> It's not normal to write binary content to stdout - you normally write

Well, I grew up in the Unix world and it is normal over there.

I am still curious which layer adds that 0xd. Is it python, cygwin, 
windows ...

Thx for reply, Andy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TurboGears /.-ed, >new == True< or >new == "True"

2005-10-12 Thread Andy Leszczynski
Sybren Stuvel wrote:
> Andy Leszczynski enlightened us with:
> 
>>should not it be:
>>
>>2 def save(self, pagename, data, submit, new):
>>3 hub.begin()
>>4 if new == True:
>>5 page = Page(pagename=pagename, data=data)
>>6 else:
>>7 page = Page.byPagename(pagename)
>>8 page.data = data
>>
>>instead of:
>>
>>4 if new == "True":
> 
> 
> No it should not. The values passed to the function are the strings
> passed by the GET request, hence all strings. There are methods of
> dealing with this - read the rest of the documentation.
> 
> Sybren

So how does it correspond to other piece of the code:

2   def notfound(self, pagename):
3   return dict(pagename=pagename, data="", new=True)

new is a boolean here?

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


creating/altering the OpenOffice spredsheet docs

2005-10-26 Thread Andy Leszczynski
Any idea how to do that the way ActiveX would be used on M$?

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


Re: Python vs Ruby

2005-10-26 Thread Andy Leszczynski
Steven D'Aprano wrote:

> 
> Every line = more labour for the developer = more cost and time.
> Every line = more places for bugs to exist = more cost and time.
>

The place I work at the creation rate is not a problem - we could crank 
out in the team 1000s lines a week. Most time we spend is on maintanance 
. This is where Pyton shines over Java/C++/Perl. It is easy to read thus 
  maintane.

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


Re: Python vs Ruby

2005-10-26 Thread Andy Leszczynski
Amol Vaidya wrote:
> Hi. I am interested in learning a new programming language, and have been 
> debating whether to learn Ruby or Python. How do these compare and contrast 
> with one another, and what advantages does one language provide over the 
> other? I would like to consider as many opinions as I can on this matter 
> before I start studying either language in depth. Any help/comments are 
> greatly appreciated. Thanks in advance for your help. 

How Ruby solves the problem of global interpreter lock?

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


pickle - recursion - stack size limit - MS windows

2005-11-05 Thread Andy Leszczynski
I need to pickle quite complex objects and first limitation was default
200 for the recursion. sys.setrecursionlimit helped, but still bigger
objects fail to be pickled because of XP stack size limitation.

Any idea how to get around the problem ...

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


Re: python + ODBC + Oracle + MySQL - money

2005-11-10 Thread rios . andy
Well having two different Databases from one app could be painful, but
I think that using Python and a "Divide and Conquer" aproach might be
your best GPL way of handling this. Start up a set of python Classes
that just does the access to the MySQL database. Get these working,
just concentrate on building the Database accesses you will need for
your app, and give the functions sensible, and relatively verbose,
names. Next take step two, doing that same thing (In a different
directory, with a slightly different naming convention for classes
maybe), but for the Oracle Database, and test that out and get that up
and running. Now you have two apps, one for MySQL and one for Oracle.

Now the step that you might not catch on about until you have more
expereience using Python. Because of the very slick and intelligent way
that Python handles naming and operator overloading you just need to
write another set of classes that is you application.
This application can just make use of the other two DB apps you just
created by calling those classes (Hence why I suggested careful naming,
and following some sort of convention for the naming). This will
eventually translate into your app, remember you can do all the fancy
User Interface work and Program Logic work in the third set of classes
(The APP classes). I'm not sure how complicated the app is, but this
sounds like a reasonalbe high level aproach. And if you boss asks
questions about this methodology just tell him/her know that you got
recommend this approach by a Graduate of the University of Toronto with
a degree in Computre Engineering. :-P

So, hope this helps, feel free to ask more questions, hopefully others
will have some more ideas to share.

My two cents,
Andy

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


[OT] Oracle 9i client for Linux

2005-11-29 Thread Andy Leszczynski
Where can I find such? I can download from Oracle whole thing but no the 
client itself.

Any insight?

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


Re: [OT] Oracle 9i client for Linux

2005-11-29 Thread Andy Leszczynski
Bernard Delmée wrote:
> Look into the Oracle Instant Client: 
>  
> (might require a -free- OTN registration)

It is version 10, would it be compatible with 9i servers?

> Be sure to download the smallish "sdk" if you want to compile client code
> (e.g. cx_oracle - highly recommended  

Indeed I use cx_oracle but on M$ yet. Want to move to Linux.

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


Re: Embedding a restricted python interpreter

2005-01-05 Thread Andy Gross
Check out 
http://mail.python.org/pipermail/python-dev/2003-January/031851.html 
for a historical thread on rexec.py's vulnerabilities.

Right now, the answer for people who want restricted execution is 
usually "wait for pypy", due to the number of tricks that can subvert 
the rexec model.  There are probably some one-off, application-specific 
things you can do that might meet your requirements, like special 
import hooks, sys.settrace() callbacks that inspect each running frame 
(and are slow), and namespace restrictions on stuff passed to exec or 
eval.  If you really need sandboxing, your probably out of luck. 
Setting up a usermode linux instance or chrooted jail is probably the 
best bet today.

/arg
On Jan 4, 2005, at 6:38 PM, Rolf Magnus wrote:
Hi,
I would like to embed a python interpreter within a program, but since 
that
program would be able to automatically download scripts from the 
internet,
I'd like to run those in a restricted environment, which basically 
means
that I want to allow only a specific set of modules to be used by the
scripts, so that it wouldn't be possible for them to remove files from 
the
hard drive, kill processes or do other nasty stuff.
Is there any way to do that with the standard python interpreter?

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


Re: a new Perl/Python a day

2005-01-09 Thread Andy Gross
On Jan 10, 2005, at 12:11 AM, Scott Bryce wrote:
No. Perl may have some interesting idiosyncrasies, especially for a 
programmer with little or no Unix experience, but I find it neither 
frustrating, inane nor incompetent. The more I use it, the more I like 
it.
I don't see what UNIX experience has to do with it.  I have plenty of 
it, and still have to look at the documentation to remember that I need 
to type '$|' to turn buffering off.  Ditto for the rest of the perl 
line-noise syntax.

/arg

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


Re: Problem in importing MySQLdb

2005-01-20 Thread Andy Dustman
Gurpreet Sachdeva wrote:

> Is there any problem in library files?? Do I need to install anything
> I have installed MySQL-shared-3.23.54a-1.i386.rpm,
> MySQL-devel-5.0.2-0.i386.rpm, MySQL-client-5.0.2-0.i386.rpm,
> MySQL-server-5.0.2-0.i386.rpm

You should recheck those version numbers carefully. One of these things
is not like the other...

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


Re: Mac OS and MySQLdb

2005-01-28 Thread Andy Dustman
The source is for all platforms. Use the Source, Luke. If 1.1.9 does
not compile on Mac OS X, file a bug.

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


Re: An mysql-python tutorial?

2005-01-29 Thread Andy Dustman
It's a pretty good tutorial, thought I would recommend you forget about
the fetchone() example. The example below demonstrates three additional
features that will make your life easier: MySQL option files, tuple
unpacking, and cursors as iterators (fourth feature: the default host
is localhost; this is rapidly turning into the Spanish Inquisition
sketch):

#!/usr/bin/python
import MySQLdb
db = MySQLdb.connect(db="db56a", read_default_file="~/.my.cnf")
cursor = db.cursor()
cursor.execute("SELECT name, species FROM animals")
for name, species in cursor:
print name, "-->", species

(I also shy away from doing SELECT *; what if your schema changes?)
(If the indentation is hosed, blame Google Groups.)

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


Re: An mysql-python tutorial?

2005-01-30 Thread Andy Dustman
It definitely looks like an access control problem; recheck your grants.

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


Re: MySQLdb - Tuples

2005-02-02 Thread Andy Dustman
#33
#! /usr/bin/env python
import MySQLdb
db=MySQLdb.connect(host='localhost', db='photum_0_6_2', user='root',
passwd='thkhgfgd')
c=db.cursor()
c.execute('select person from persons order by person')
for (person,) in c: # or c.fetchall() (may be more portable)
print person


If you return more than one column, then you don't need the parentheses
for the tuple unpacking. MySQLdb (and all other DB API databases)
return rows as tuples, so if you only select one column, you get a
tuple of one item.

(google groups eats leading spaces)

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


Re: Install MySQL-python-0.9.1

2005-06-21 Thread Andy Dustman
Cathy  Hui wrote:
> I am trying to install MySQL-Python 0.9.1 on my Solaris 8 system.  The
> system has Python 2.3.3 and Mysql 4.0.21 installed.

You're wasting your time. Use MySQL-python-1.2.0.

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


Re: How to connect python and Mysql?

2005-06-29 Thread Andy Dustman
Post your question here:
http://sourceforge.net/forum/forum.php?forum_id=70461

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


Re: Python, mysql, floating point values question

2005-07-03 Thread Andy Dustman
Use DECIMAL columns with MySQLdb-1.2.0 and Python-2.4 and you should
get values back using Python's new decimal type.

http://docs.python.org/whatsnew/node9.html

This avoids floating point inaccuracies.

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


Berkely DB – many writers, many rea ders

2005-07-07 Thread Andy Leszczynski


I need to now option I open the Berkley DB (both db and env) to have 
configuration for multiple writers and multiple readers.  Via multiple 
processes  and multiple threads. No trx needed.

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


Re: Cursor navigation

2005-07-19 Thread Andy Dustman
TA wrote:
> Hi,
>
> This might be a silly question, but I was wondering how you would navigate
> backwards in a PostgreSQL cursor when the Python DB-API 2.0 allows records
> to be fetched in a forward-only manner?

This is untrue: cursor.scroll() is an optional DB-API 2.0 extension.

http://www.python.org/peps/pep-0249.html

MySQLdb supports this, but I do not know about your case.

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


>time.strftime %T missing in 2.3

2005-08-04 Thread Andy Leszczynski
Python 2.2/Unix

 >>time.strftime("%T")
'22:12:15'
 >>time.strftime("%X")
'22:12:17'

Python 2.3/Windows

 >>time.strftime("%X")
'22:12:47'
 >> time.strftime("%T")
''

Any clues?

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


Re: >time.strftime %T missing in 2.3

2005-08-04 Thread Andy Leszczynski
Robert Kern wrote:
> Andy Leszczynski wrote:
> 
>> Python 2.2/Unix
>>
>>  >>time.strftime("%T")
>> '22:12:15'
>>  >>time.strftime("%X")
>> '22:12:17'
>>
>> Python 2.3/Windows
>>
>>  >>time.strftime("%X")
>> '22:12:47'
>>  >> time.strftime("%T")
>> ''
> 
> 
>  From http://docs.python.org/lib/node252.html
> 
> """The full set of format codes supported varies across platforms, 
> because Python calls the platform C library's strftime() function, and 
> platform variations are common."""
> 
> So I suggest that it's a platform issue, not a Python version issue. FWIW:
> 
> Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
> [GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> import time
>  >>> time.strftime("%T")
> '22:50:49'
>  >>> time.strftime("%X")
> '22:50:59'
> 

I accept that, but still pain. Took me a while to filter out the problem 
in the code running on the Unix and not on M$.

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


Re: Berkely DB – many writers, many readers

2005-08-06 Thread Andy Leszczynski
Eric S. Johansson wrote:
> Andy Leszczynski wrote:
> 
>>
>> I need to now option I open the Berkley DB (both db and env) to have 
>> configuration for multiple writers and multiple readers.  Via multiple 
>> processes  and multiple threads. No trx needed.
> 
> 
> the simple answer is you can't.  bdbm is probably single writer multiple 
> reader.  I believe if you use of the the most recent sleepy cat 
> database, you have support for multiple readers and writers in any context.
[...]

I have learned later that you can, just use Concurrent DB poruct 
(db.DB_INIT_CDB):

...envflags=db.DB_CREATE|db.DB_INIT_MPOOL|db.DB_THREAD|db.DB_INIT_CDB
...env.open(file,envflags)

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


Python supports LSP, does it?

2005-08-09 Thread Andy Leszczynski
wikipedia 
(http://en.wikipedia.org/wiki/Python_programming_language#Object-oriented_programming)
 
says:
"""
Python's support for object oriented programming paradigm is vast. It 
supports polymorphism [...] fully in the Liskov substitution 
principle-sense for all objects.
"""

Just wondering if it is true statement. Is not LSP more a quality of the 
desing of class hierachy rather then language itslef? Comments?

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


  1   2   3   4   >