Re: Importing a file (not a module).

2009-02-09 Thread Hendrik van Rooyen
"Luis Zarrabeitia"  wrote:

>Is there any way to "import" a .py file that is not on sys.path?
>I'd like to 'import' a file that resides somewhere on my filesystem without
>having to add it's directory to sys.path. At first, I thought that something
like
>
>my_module = __import__("path/to/file")
>
>would work, but I was mistaken. Ideally, the path would be specified as a
>relative path from the importer's module, and not from the CWD (that's another
>question, I guess).

I have used execfile(RelativeFromCWDOrAbsolutePathToTheFile) to do
this sort of thing. But beware - it does not create a module, so it's a bit
like:

from something import *

This may or may not be useful in your case.

- Hendrik


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


Re: Simple question - stock market simulation

2009-02-09 Thread Hendrik van Rooyen
"cptn.spoon"  wrote:

On Feb 9, 3:58 pm, Paul Rubin  wrote:

>Thanks Paul! I thought this might be the case. So how would I get the
>StockMarket class instance to contain many Stock class instances and
>then be able to iterate through them? I'm guessing the basic structure
>would be as follows...but I think I'm wrong:
>
>class StockMarket:
>  pass

No.
At this level, just use a list of instances of your Stock class.

- Hendrik


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


Local python web server problem

2009-02-09 Thread Farsheed Ashouri
Hi everyone. I have started to develop a web base software for
renderfarm managing.
I run the cherrypy hello world! example and when I visit
127.0.0.1:8080
on firefox, a nice "Hello World" appears. I am on ubuntu and my ip in
local network is 192.168.100.18
but when I visit 192.168.100.18, there is another page: "It Works!".
What is "It Works!"? and when I type 192.168.100.18:8080 in another
local pc, the page didn't load?

Sorry I am newbie in network area, so I have these two questions:
1- How can I serve my page in local network?
2- what is "It Works!" in 192.168.100.18? we have
192.168.100.<10-70> . no pc has this but mine!!!

3- Could you please explain me or at least point me to the right
direction of making little local web server, localhost?

4- How can I access to the server that serves web page in 56566 port?
I try 192.168.100.18:56566
but the page could not load. I can ping 192.168.100.18 but I can't
load web pages from it.
Why?


Thanks and sorry for my bad English.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python binaries with VC++ 8.0?

2009-02-09 Thread Mark Hammond

On 9/02/2009 5:51 PM, Greg Ewing wrote:

Is there anywhere I can download a set of Python
binaries, of any version, that have been built
with Visual C++ 8.0?


IIRC, no.  Python skipped that version of MSVC.  I believe Python 2.5 
builds easily with vc8 project files in svn though.



I'm trying to hook Python up to Sketchup 7 on
Windows, and I think I'm having problems because
Sketchup is linked with msvcr80.dll.


What problems specifically?  The only practical problems you should see 
will arise if you try and pass a "FILE *", or allocate memory you then 
ask python to free (or vice-versa) - both should be avoidable though...


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


Small socket problem

2009-02-09 Thread John O'Hagan
Hi, 

I'm using the socket module (python 2.5) like this (where 'options' refers to 
an optparse object) to connect to the Fluidsynth program:

host = "localhost"
port = 9800
fluid = socket(AF_INET, SOCK_STREAM)
try:
fluid.connect((host, port))  #Connect if fluidsynth is running
except BaseException:
print "Connecting to fluidsynth..." #Or start fluidsynth
soundfont =  options.soundfont
driver = options.driver
Popen(["fluidsynth", "-i", "-s", "-g", "0.5",
"-C", "1",  "-R", "1", "-l", "-a", driver, "-j", soundfont])
timeout = 50
while 1:
timeout -= 1
if timeout == 0:
print "Problem with fluidsynth: switching to synth."
play_method = "synth"
break
try:
fluid.connect((host, port))
except BaseException:
sleep(0.05)
continue
else:
break

(I'm using BaseException because I haven't been able to discover what 
exception class[es] socket uses).

The problem is that this fails to connect ( the error is "111: Connection 
refused") the first time I run it after booting if fluidsynth is not already 
running, no matter how long the timeout is; after Ctrl-C'ing out of the 
program, all subsequent attempts succeed. Note that fluidsynth need not be 
running for a success to occur. 

I've also tried it without the while loop, simply sleeping for a few seconds 
to give fluidsynth time to start (not a preferred approach as I want a short 
startup), but the same thing happens.

I am a long way from being a networking guru and am at a loss as to how to 
debug this. Maybe someone can point out some flaw in my use of socket.

Thanks,

John O'Hagan
--
http://mail.python.org/mailman/listinfo/python-list


RE: How to copy an instance without its cStringIO.StringO item ?

2009-02-09 Thread Barak, Ron
Hi John,

Thanks for the suggestion.

What I do now in preparation for pickling is:

for_pickle_log_stream = LogStream(sac_log_file)
for key in log_stream.__dict__:
if key != "input_file":
for_pickle_log_stream.__dict__[key] = 
log_stream.__dict__[key]
del for_pickle_log_stream.__dict__["input_file"]

(i.e., log_stream is the source instance, and for_pickle_log_stream is the 
target)

So, it seems to be in agreement with your suggestion.

Thanks and bye,
Ron.

-Original Message-
From: John Machin [mailto:sjmac...@lexicon.net]
Sent: Sunday, February 08, 2009 23:04
To: python-list@python.org
Subject: Re: How to copy an instance without its cStringIO.StringO item ?

On Feb 9, 1:01 am, Christian Heimes  wrote:
> Barak, Ron schrieb:
>
> > Hi,
>
> > I need to copy an instance of a class, where one of the items in the 
> > original is a cStringIO.StringO object.
> > I do not need the cStringIO.StringO in the target object.
> > The target instance is to be pickled.
>
> > Googling made me devise the following plan: do a deepcopy from the original 
> > to the target, and then delete the cStringIO.StringO object from the target.
>
> > However, trying to use copy.deepcopy produced: TypeError:
> > object.__new__(cStringIO.StringO) is not safe, use
> > cStringIO.StringO.__new__()
>
> > Is there a way to create a copy of the instance, sans the cStringIO.StringO 
> > ?
>
> > If I find no elegant way to do that, I thought of creating a "blank" target 
> > instance; then iterating over the __dict__ of the original, and manually 
> > copy the items to the target (while not copying the cStringIO.StringO to 
> > the target).
>
> > Can you suggest a better way ?
>
> You can overwrite some functions in order to omit attributes from a
> pickle. It's all documented 
> athttp://docs.python.org/library/pickle.html#pickling-and-unpickling-no...

If there is no chance that some other thread could be accessing the source 
object, can't the OP just do:
temp = source.stringio
del source.stringio
# make a pickle from source
source.stringio = temp
?




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


Re: Python Module: nift

2009-02-09 Thread bearophileHUGS
Steven D'Aprano:
> There's less code, fewer bugs and lines. Less applies to continuous
> quantities, like weight and "amount of code", and fewer applies to
> countable quantities.

Thank you, I'll try to improve my use of the language.


> Within reason, naturally. There's a reason why we write:
> for button in buttons:
>     move(button, delta_x, delta_y)
> instead of
> for b in bs: mv(b, x, y)
> even though the second is significantly shorter.

Often Shortening names and packing more stuff in single lines that
deserve to be two lines aren't good ways to shorten code.


> Also, I don't think there's much advantage in trying to push new
> programmers to reduce the amount of code. Until you're really comfortable
> with the language, you need training wheels and scaffolding in the form
> of verbose code. Sometimes you really don't appreciate Python's labour
> saving features until you've experienced how much labour there is to be
> saved.

I don't agree. When you learn to code you also have to learn what does
it mean to write "good code", you have to learn that there are several
things that are important beside writing a correct output, like good
comments, well thought out names, good indentation, good idioms, quick
running time, small memory usage, writing clear and readable code, and
later develop elegance, the power of composition, abstraction,
indirection, meta programming, etc. Among such things there's the
importance of writing short programs. All such things are the seeds
that will develop into the personal style of the future programmer.

Such things are also useful for another purpose: to help the student
understand that code is craftsmanship, so she/he/shi can (and is
supposed to) be proud of the code that writes. This helps the student
understand that programming isn't just an ugly way to tell orders to a
moronic CPU, that helps develop appreciation for the act of writing
code, because it becomes something you do also for the sake of it, as
you do art, beside for usefulness. So you have to teach and show such
things from more or less the beginning.

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Variable + String Format

2009-02-09 Thread Joel Ross

Hi all,

I have this piece of code:
#

wordList = "/tmp/Wordlist"
file = open(wordList, 'r+b')


def readLines():

for line in file.read():
if not line: break
print line + '.com '
return line



readLines()
file.close()

##

It returns the results:

t.com

NOTE: Only returns the first letter of the first word on the first line 
e.g. test would only print t and readline() does the same thing.


I have also tried readlines() which gives me the result:

test
.com

The file Wordlist has one word on each line for example

test
test1
test2

I need it to loop though the Wordlist file and print/return the results

test.com
test1.com
test2.com

I'm just looking for a point in the right direction.

Much Thanks

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


Re: Variable + String Format

2009-02-09 Thread Chris Rebert
On Tue, Feb 10, 2009 at 2:03 AM, Joel Ross  wrote:
> Hi all,
>
> I have this piece of code:
> #
>
> wordList = "/tmp/Wordlist"
> file = open(wordList, 'r+b')

Why are you opening the file in binary mode? It's content is text!

>
> def readLines():
>
>for line in file.read():

.read() reads the *entire* file into a string. When you iterate over a
string, such as in a for-loop, you get *individual characters*,
whereas you appear to want lines of text. To go line-by-line, use `for
line in file` instead (note: `line` will include the trailing newline
at the end of each line).
And don't use `file` as a variable name; it shadows the name of the
buitlin type.

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to copy an instance without its cStringIO.StringO item ?

2009-02-09 Thread John Machin

On 9/02/2009 8:51 PM, Barak, Ron wrote:

Hi John,

Thanks for the suggestion.

What I do now in preparation for pickling is:

for_pickle_log_stream = LogStream(sac_log_file)   
for key in log_stream.__dict__:

if key != "input_file":
for_pickle_log_stream.__dict__[key] = 
log_stream.__dict__[key]
del for_pickle_log_stream.__dict__["input_file"]   

(i.e., log_stream is the source instance, and for_pickle_log_stream is 
the target)


So, it seems to be in agreement with your suggestion.


which was
"""
 If there is no chance that some other thread could be accessing the
 source object, can't the OP just do:
 temp = source.stringio
 del source.stringio
 # make a pickle from source
 source.stringio = temp
"""
which I regard as radically different to your approach; please explain 
what you mean by "in agreement with".



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


Re: Variable + String Format

2009-02-09 Thread John Machin
On Feb 9, 9:13 pm, Chris Rebert  wrote:
> On Tue, Feb 10, 2009 at 2:03 AM, Joel Ross  wrote:
> > Hi all,
>
> > I have this piece of code:
> > #
>
> > wordList = "/tmp/Wordlist"
> > file = open(wordList, 'r+b')
>
> Why are you opening the file in binary mode? It's content is text!
>
>
>
> > def readLines():
>
> >        for line in file.read():
>
> .read() reads the *entire* file into a string. When you iterate over a
> string, such as in a for-loop, you get *individual characters*,
> whereas you appear to want lines of text. To go line-by-line, use `for
> line in file` instead (note: `line` will include the trailing newline
> at the end of each line).
> And don't use `file` as a variable name; it shadows the name of the
> buitlin type.
>

Changed as suggested above, with further comments:

wordList = "/tmp/Wordlist"
f = open(wordList, 'r')
def readLines():
## There is no point in putting the next four lines
## inside a function if you are going to call the
## function (a) immediately and (b) once only.
## All it does is provide scope for unwanted complications.
   for line in f:
line = line.rstrip('\n')
print line + '.com '
## Complications like this next line; why is it returning "line"??
## And why is it indented like that?
## It will cause only the first line to be read.
return line
## Maybe you you meant it to be here:
return
## But then it's redundant because a function returns anyway
## when flow of control would fall off the bottom.
readLines()
f.close()

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


Re: Tkinter w.pack()?

2009-02-09 Thread Pete Forman
"W. eWatson"  writes:

 > MRAB wrote:
>> W. eWatson wrote:
 > ...
>>> I thought some months ago, I found Google commands that would
>>> operate in the browser link window. Guess not.
>>>
>>> BTW, isn't there an O'Reilly book on Google hacks of this sort? 
>>> Where else does one find out about these Google tools?
>>>
>> Google? :-)
>> http://www.google.com/support/websearch/bin/answer.py?hl=en&answer=136861
>>
 > Thanks. I may have that book marked from many, many months ago. If so,
 > I see why I'd never find it. The BM entry does not show "Google". It
 > does now. ;-)

As well as the site: modifier check out inurl: and friends.

  http://www.google.com/help/operators.html

-- 
Pete Forman-./\.-  Disclaimer: This post is originated
WesternGeco  -./\.-   by myself and does not represent
pete.for...@westerngeco.com-./\.-   the opinion of Schlumberger or
http://petef.22web.net   -./\.-   WesternGeco.
--
http://mail.python.org/mailman/listinfo/python-list


Which core am I running on?

2009-02-09 Thread psaff...@googlemail.com
Is there some way I can get at this information at run-time? I'd like
to use it to tag diagnostic output dumped during runs using Parallel
Python.

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


Re: Local python web server problem

2009-02-09 Thread Gerhard Häring
Farsheed Ashouri wrote:
> Hi everyone. I have started to develop a web base software for
> renderfarm managing.
> I run the cherrypy hello world! example and when I visit
> 127.0.0.1:8080
> on firefox, a nice "Hello World" appears. I am on ubuntu and my ip in
> local network is 192.168.100.18
> but when I visit 192.168.100.18, there is another page: "It Works!".
> What is "It Works!"? and when I type 192.168.100.18:8080 in another
> local pc, the page didn't load? [...]

Services like HTTP servers "bind" not only to a port, but to a
combination of IP address and port.

The CherryPy tutorial configuration

http://www.cherrypy.org/browser/trunk/cherrypy/tutorial/tutorial.conf

binds to 127.0.0.1 and 8080. This means the application can only be
accessed from the local machine.

To bind to all network interfaces, (i. e. Ethernet etc., and not just
the loopback device), you can change server.socket_host to "0.0.0.0".

-- Gerhard

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


Re: Which core am I running on?

2009-02-09 Thread Gerhard Häring
psaff...@googlemail.com wrote:
> Is there some way I can get at this information at run-time? I'd like
> to use it to tag diagnostic output dumped during runs using Parallel
> Python.

Looks like I have answered a similar question once, btw. ;-)

http://objectmix.com/python/631346-parallel-python.html

-- Gerhard

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


Re: Which core am I running on?

2009-02-09 Thread Gerhard Häring
psaff...@googlemail.com wrote:
> Is there some way I can get at this information at run-time? I'd like
> to use it to tag diagnostic output dumped during runs using Parallel
> Python.

There should be a way, but not with the Python standard library. It's
also platform-specific. What are you using? Linux, MacOS X, FreeBSD,
Solaris, or maybe Windows?

-- Gerhard

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


Re: Which core am I running on?

2009-02-09 Thread psaff...@googlemail.com
On 9 Feb, 12:24, Gerhard Häring  wrote:
> Looks like I have answered a similar question once, btw. ;-)
>

Ah, yes - thanks. I did Google for it, but obviously didn't have the
right search term.

Cheers,

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


Too many open files

2009-02-09 Thread psaff...@googlemail.com
I'm building a pipeline involving a number of shell tools. In each
case, I create a temporary file using tempfile.mkstmp() and invoke a
command ("cmd < /tmp/tmpfile") on it using subprocess.Popen.

At the end of each section, I call close() on the file handles and use
os.remove() to delete them. Even so I build up file descriptors that
eventually give me the "too many files" error message. Am I missing
something here?

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


convert the ip packet to and from RS-232 packet

2009-02-09 Thread Li Han
Hi, I need to use radio to connect two local ip network, each local
network has a server computer which connects to a radio with RS-232
interface.  I need to write a program to convert the local ip packet
into RS-232 packet, so the radio can send packetes to the remote
radio. I don't want to reinvent the wheel, is there anyone could give
me some suggestions?
Thank you!
Han
--
http://mail.python.org/mailman/listinfo/python-list


wxPython vs Glade?

2009-02-09 Thread Michael Pobega
I'm looking for opinions on the best toolkit for a beginner to use with
wxPython. It doesn't necessarily need to be the most efficient toolkit,
but something I can use for basic programs (a Twitter client, Wordpress
blogging client, etc) just to learn Python.

wxWidgets seems nice because it's portable, but I'm not sure how many of
my libraries are portable (a lot of them seem to import os), while Glade
seems extremely simple to make a UI (but does the program end up relying
on Glade? Or can I build it directly into GTK+?)

-- 
  http://pobega.wordpress.com
http://identica/pobega


signature.asc
Description: Digital signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: Too many open files

2009-02-09 Thread Ulrich Eckhardt
psaff...@googlemail.com wrote:
> I'm building a pipeline involving a number of shell tools. In each
> case, I create a temporary file using tempfile.mkstmp() and invoke a
> command ("cmd < /tmp/tmpfile") on it using subprocess.Popen.
> 
> At the end of each section, I call close() on the file handles and use
> os.remove() to delete them. Even so I build up file descriptors that
> eventually give me the "too many files" error message. Am I missing
> something here?

There recently was a bug filed at bugs.python.org about leaked file
descriptors. Maybe that is exactly what you are experiencing here.

Uli

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

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


Re: convert the ip packet to and from RS-232 packet

2009-02-09 Thread Steve Holden
Li Han wrote:
> Hi, I need to use radio to connect two local ip network, each local
> network has a server computer which connects to a radio with RS-232
> interface.  I need to write a program to convert the local ip packet
> into RS-232 packet, so the radio can send packetes to the remote
> radio. I don't want to reinvent the wheel, is there anyone could give
> me some suggestions?
> Thank you!

There's a package called pyserial that's pretty good at handling RS-232
interfaces. Good luck!

regards
 Steve
(G3VEK)
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: wxPython vs Glade?

2009-02-09 Thread Benjamin Kaplan
On Mon, Feb 9, 2009 at 8:23 AM, Michael Pobega  wrote:

> I'm looking for opinions on the best toolkit for a beginner to use with
> wxPython. It doesn't necessarily need to be the most efficient toolkit,
> but something I can use for basic programs (a Twitter client, Wordpress
> blogging client, etc) just to learn Python.
>
> wxWidgets seems nice because it's portable, but I'm not sure how many of
> my libraries are portable (a lot of them seem to import os), while Glade
> seems extremely simple to make a UI (but does the program end up relying
> on Glade? Or can I build it directly into GTK+?)
>


wxPython is the toolkit. It provides Python wrappers for wxWidgets. I think
you are looking at wxGlade, a UI designer for wx based off of the Gnome UI
builder. It's not a toolkit..

>
> --
>  http://pobega.wordpress.com
>http://identica/pobega
>
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iEYEARECAAYFAkmQLkkACgkQxgy5R7EobNd/vwCfeDdaeX6YyNxcCZ11pmbWMPZj
> akwAn2LCb3Qz2lLKZLF3DG4j5lTBOQdd
> =/Bfe
> -END PGP SIGNATURE-
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython vs Glade?

2009-02-09 Thread Steve Holden
Michael Pobega wrote:
> I'm looking for opinions on the best toolkit for a beginner to use with
> wxPython. It doesn't necessarily need to be the most efficient toolkit,
> but something I can use for basic programs (a Twitter client, Wordpress
> blogging client, etc) just to learn Python.
> 
> wxWidgets seems nice because it's portable, but I'm not sure how many of
> my libraries are portable (a lot of them seem to import os), while Glade
> seems extremely simple to make a UI (but does the program end up relying
> on Glade? Or can I build it directly into GTK+?)
> 
There's something called PythonCard built on top of wxPython that's
fairly newb-friendly, though it gets clunkier as your demands grow.

You might also want to look at Dabo, which is a much more comprehensive
framework that also hides much of wxPython's complexity.

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


BeautifulSoup -converting unicode to numerical representaion

2009-02-09 Thread S.Selvam Siva
Hi all,

I need to parse feeds and post the data to SOLR.I want the special
characters(Unicode char) to be posted as numerical representation,

For eg,
*'* --> ’ (for which HTML equivalent is ’)
I used BeautifulSoup,which seems to be allowing conversion from "&#;"(
numeric values )to unicode characters as follow,

*hdes=str(BeautifulStoneSoup(strdesc,
convertEntities=BeautifulStoneSoup.HTML_ENTITIES))
xdesc=str(BeautifulStoneSoup(hdes,
convertEntities=BeautifulStoneSoup.XML_ENTITIES))*

But i want *numerical representation of unicode characters.*
I also want to convert html representation like ’ to its numeric
equivalent ’

Thanks in advance.

*Note:*
The reason for the above requirement is i need a standard way to post to
SOLR to avoid errors.
-- 
Yours,
S.Selvam
--
http://mail.python.org/mailman/listinfo/python-list


Re: convert the ip packet to and from RS-232 packet

2009-02-09 Thread Tino Wildenhain

Hi,

Li Han wrote:

Hi, I need to use radio to connect two local ip network, each local
network has a server computer which connects to a radio with RS-232
interface.  I need to write a program to convert the local ip packet
into RS-232 packet, so the radio can send packetes to the remote
radio. I don't want to reinvent the wheel, is there anyone could give
me some suggestions?


You might want to check:

http://en.wikipedia.org/wiki/Packet_radio


some free OS already come with an interface
implemention so all you need would be configuring
that interface and routing appropriately.

As such, not really a python topic.

Regards
Tino


smime.p7s
Description: S/MIME Cryptographic Signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: Which core am I running on?

2009-02-09 Thread psaff...@googlemail.com
On 9 Feb, 12:24, Gerhard Häring  wrote:
> http://objectmix.com/python/631346-parallel-python.html
>

Hmm. In fact, this doesn't seem to work for pp. When I run the code
below, it says everything is running on the one core.

import pp
import random
import time
from string import lowercase

ncpus = 3

def timedCharDump(waittime, char):
time.sleep(waittime)
mycore = open("/proc/%i/stat" % os.getpid()).read().split()[39]
print "I'm doing stuff!", mycore, char
return char

job_server = pp.Server(ncpus, ppservers=())

jobdetails = [ (random.random(), letter) for letter in lowercase ]

jobs = [ job_server.submit(timedCharDump,(jinput1, jinput2), (),
("os", "time",)) for jinput1, jinput2 in jobdetails ]

for job in jobs:
print job()


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


cannot install

2009-02-09 Thread Vladimír Župka
I have Mac OS X Leopard 10.5.6 and I downloaded and unpacked Python  
3.0 into a folder (/Library/Frameworks/Python.framework) and ran  
commands:


cd /Library/Frameworks/Python.framework/Python-3.0
python setup.py install

and got the message reporting a syntax error:

Macintosh:~ vzupka$ /bin/csh
[Macintosh:~] vzupka% cd /Library/Frameworks/Python.framework/Python-3.0
[Macintosh:Frameworks/Python.framework/Python-3.0] vzupka% python  
setup.py install

  File "setup.py", line 232
except (CCompilerError, DistutilsError) as why:
 ^
SyntaxError: invalid syntax
[Macintosh:Frameworks/Python.framework/Python-3.0] vzupka%

What is the reason and how do I install?

Regards,
Vladimír Župka
vzu...@volny.cz





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


thread. question

2009-02-09 Thread Tim Wintle
Hi, 
This is my first post here - google hasn't helped much but sorry if this
has been asked before.

I've been wondering about some of the technicalities of locks in python
(2.4 and 2.5 mainly).

I'm using the "old" thread module as (1) I prefer the methods and (2) It
should be a tiny bit faster.

As far as I can see, the thread module is fairly much a direct wrapper
around "PyThread_allocate_lock" etc. - defined in
"thread_pthread.h" (took me ages to find the definitions in a header
file!), so as far as I can tell the implementation is very closely
wrapped around the system's threading implementation. 

Does that mean that every python thread is actually a real separate
thread (for some reason I thought they were implemented in the
interpreter)?

Does that also mean that there is very little extra interpreter-overhead
to using locks (assuming they very infrequently block)? Since if you use
the thread module direct the code doesn't seem to escape from C during
the acquire() etc. or am I missing something important?

Thanks,

Tim Wintle




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


Re: Small socket problem

2009-02-09 Thread Gabriel Genellina
En Mon, 09 Feb 2009 07:43:36 -0200, John O'Hagan   
escribió:


I'm using the socket module (python 2.5) like this (where 'options'  
refers to

an optparse object) to connect to the Fluidsynth program:

host = "localhost"
port = 9800
fluid = socket(AF_INET, SOCK_STREAM)
try:
fluid.connect((host, port))  #Connect if fluidsynth is  
running

except BaseException:
print "Connecting to fluidsynth..." #Or start fluidsynth
soundfont =  options.soundfont
driver = options.driver
Popen(["fluidsynth", "-i", "-s", "-g", "0.5",
"-C", "1",  "-R", "1", "-l", "-a", driver, "-j",  
soundfont])

timeout = 50
while 1:
timeout -= 1
if timeout == 0:
print "Problem with fluidsynth: switching to  
synth."

play_method = "synth"
break
try:
fluid.connect((host, port))
except BaseException:
sleep(0.05)
continue
else:
break

(I'm using BaseException because I haven't been able to discover what
exception class[es] socket uses).


Usually socket.error, which is a subclass of IOError, but others might  
happen too I think. In any case, the most generic except clause you should  
use is

try:
except Exception: ...
(because you usually don't want to catch KeyboardInterrupt nor SystemExit,  
that is, let Ctrl-C and sys.exit() do their work)



The problem is that this fails to connect ( the error is "111: Connection
refused") the first time I run it after booting if fluidsynth is not  
already

running, no matter how long the timeout is; after Ctrl-C'ing out of the
program, all subsequent attempts succeed. Note that fluidsynth need not  
be

running for a success to occur.


Always the same exception? In both lines?

--
Gabriel Genellina

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


Re: wxPython vs Glade?

2009-02-09 Thread Michael Pobega
On Mon, Feb 09, 2009 at 08:30:13AM -0500, Benjamin Kaplan wrote:
> On Mon, Feb 9, 2009 at 8:23 AM, Michael Pobega  wrote:
> 
> > I'm looking for opinions on the best toolkit for a beginner to use with
> > wxPython. It doesn't necessarily need to be the most efficient toolkit,
> > but something I can use for basic programs (a Twitter client, Wordpress
> > blogging client, etc) just to learn Python.
> >
> > wxWidgets seems nice because it's portable, but I'm not sure how many of
> > my libraries are portable (a lot of them seem to import os), while Glade
> > seems extremely simple to make a UI (but does the program end up relying
> > on Glade? Or can I build it directly into GTK+?)
> >
> 
> wxPython is the toolkit. It provides Python wrappers for wxWidgets. I think
> you are looking at wxGlade, a UI designer for wx based off of the Gnome UI
> builder. It's not a toolkit..
> 

No, I'm not. You don't have to argue semantics with me; I'm talking
about using wxPython directly (i.e. with Vim) or using Glade to build an
interface; I'm wondering which makes for the easiest and best end result
code.

-- 
  http://pobega.wordpress.com
http://identica/pobega


signature.asc
Description: Digital signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: MacPython 2.5 IDLE font size

2009-02-09 Thread Scott David Daniels

I (Scott David Daniels) wrote:

choha...@gmail.com wrote:

Is there a way to adjust the default font size in IDLE, in MacPython
2.5? The default now is too tiny.
I have to use this version of MacPython. As far as I searched, I can't
find how I do this.


If you can read what you have at all, try to go toHelp (on the top),
then down in that menu to "Configure IDLE ..."
There will be a possibly long delay.  Then on the tab in the produced
window, You can set the Base Editor Font and Size.  I use Tahoma 14.
Then go click "Ok".  If the display doesn't get better, you might have
to exit from Idle and restart it.  If this doesn't work, get back to me
and we can try something more drastic.


Although the OP seems no longer interested,  I'd now advise anyone
interested yo read the entire section on installing VPython (v5) on
OS/X.  It has a very clear set of things to do to get Python 2.5 and
IDLE working.  You can simply skip the steps for downloading and
installing VPython if you like.
http://www.vpython.org/contents/download_mac.html

As to why it is on vpython.org rather than python.org, VPython is used
in physics courses at a number of universities, and they teach their
classes (to people not necessarily programmers) using IDLE to interact
with and program their physics demos (3-D images that you can mouse
around to change your point of view).

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


Re: Variable + String Format

2009-02-09 Thread Gabriel Genellina

En Tue, 10 Feb 2009 08:03:06 -0200, Joel Ross  escribió:


#

wordList = "/tmp/Wordlist"
file = open(wordList, 'r+b')


def readLines():

 for line in file.read():
 if not line: break
 print line + '.com '
 return line



readLines()
file.close()

##

It returns the results:

t.com

NOTE: Only returns the first letter of the first word on the first line  
e.g. test would only print t and readline() does the same thing.


This should print every line in the file, adding .com at the end:

wordList = "/tmp/Wordlist"
with open(wordList, 'r') as wl:
  for line in wl:
print line.rstrip() + '.com '

Note that:
- I iterate over the file self; files are their own line-iterators.
- I've used the 'r' mode instead (I assume it's a text file because you  
read it line by line, and as you don't update it, the '+' isn't required)
- the line read includes the end-of-line '\n' at the end; rstrip() removes  
it and any trailing whitespace. If you don't want this, use rstrip('\n')

- I've used the with statement to ensure the file is closed at the end


--
Gabriel Genellina

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


Re: Variable + String Format

2009-02-09 Thread Gabriel Genellina

En Tue, 10 Feb 2009 08:03:06 -0200, Joel Ross  escribió:


#

wordList = "/tmp/Wordlist"
file = open(wordList, 'r+b')


def readLines():

 for line in file.read():
 if not line: break
 print line + '.com '
 return line



readLines()
file.close()

##

It returns the results:

t.com

NOTE: Only returns the first letter of the first word on the first line  
e.g. test would only print t and readline() does the same thing.


This should print every line in the file, adding .com at the end:

wordList = "/tmp/Wordlist"
with open(wordList, 'r') as wl:
  for line in wl:
print line.rstrip() + '.com '

Note that:
- I iterate over the file self; files are their own line-iterators.
- I've used the 'r' mode instead (I assume it's a text file because you  
read it line by line, and as you don't update it, the '+' isn't required)
- the line read includes the end-of-line '\n' at the end; rstrip() removes  
it and any trailing whitespace. If you don't want this, use rstrip('\n')

- I've used the with statement to ensure the file is closed at the end


--
Gabriel Genellina

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


Py2app Py2exe and losing extensibility

2009-02-09 Thread member Basu
I'm currently working on a project that allows users to write their own
Python modules as simple extensions (basically output formatters). I would
like to do a cross-platform release and so I'm using PyQt and will be trying
to convert it to native builds using Py2app and Py2xe. I don't want users to
have to install Qt and PyQt to run it. But if I do that, will I still be
able to load Python modules dynamically as extensions ? (assuming that the
user machine has Python installed separately).
Thanks,
Basu
--
http://mail.python.org/mailman/listinfo/python-list


Re: convert the ip packet to and from RS-232 packet

2009-02-09 Thread bobicanprogram
On Feb 9, 8:13 am, Li Han  wrote:
> Hi, I need to use radio to connect two local ip network, each local
> network has a server computer which connects to a radio with RS-232
> interface.  I need to write a program to convert the local ip packet
> into RS-232 packet, so the radio can send packetes to the remote
> radio. I don't want to reinvent the wheel, is there anyone could give
> me some suggestions?
> Thank you!
> Han


You might want to check out the SIMPL toolkit. (http://
www.icanprogram.com/simpl).   It come standard with an RS232
surrogate.   This generic module will transparently transmit a SIMPL
message via RS232 serial connection.   Although this module is written
in C,  SIMPL itself fully supports Python as a language to create
modules.

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


Re: thread. question

2009-02-09 Thread bieffe62
On Feb 9, 2:47 pm, Tim Wintle  wrote:
> Hi,
> This is my first post here - google hasn't helped much but sorry if this
> has been asked before.
>
> I've been wondering about some of the technicalities of locks in python
> (2.4 and 2.5 mainly).
>
> I'm using the "old" thread module as (1) I prefer the methods and (2) It
> should be a tiny bit faster.
>
> As far as I can see, the thread module is fairly much a direct wrapper
> around "PyThread_allocate_lock" etc. - defined in
> "thread_pthread.h" (took me ages to find the definitions in a header
> file!), so as far as I can tell the implementation is very closely
> wrapped around the system's threading implementation.
>
> Does that mean that every python thread is actually a real separate
> thread (for some reason I thought they were implemented in the
> interpreter)?
>

I've hever seen the C implementation of python thread, but I know that
python threads
are real OS threads, not 'green threads' inside the interpreter.


> Does that also mean that there is very little extra interpreter-overhead
> to using locks (assuming they very infrequently block)? Since if you use
> the thread module direct the code doesn't seem to escape from C during
> the acquire() etc. or am I missing something important?
>

One significant difference with doing threads in lower level languages
is that in Python the single interpreter instructions
are atomic. This make things a bit safer but also less reactive. It is
especially bad if you use C modules which have function
calls which take long time (bit AFAIK most of IO standard modules have
work around for it),
because your program will not change thread until the C function
returns.
The reason - or one of the reasons - for this is that the python
threads share the interpreter, which is locked
by a thread before execution of a statement and released at the end
(  this is the 'Global Interpreter Lock' or GIL of
which you probably found many references if you googled for python
threads ). Among the other things, this seem to mean that
a multi-threaded python application cannot take full advantage of
multi-core CPUs (but the detailed reason for that escapes me...).

For these reasons, on this list, many suggest that if you have real-
time requirements, probably you should consider using
sub-processes instead of threads.
Personally I have used  threads a few times, although always with
very  soft real-time requirements, and I have never been bitten by the
GIL (meaning that anyway I was able top meet my timing requirements).
So, to add another achronym to my post, YMMV.


> Thanks,
>
> Tim Wintle

Ciao

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


Re: thread. question

2009-02-09 Thread Christian Heimes
Tim Wintle schrieb:
> Hi, 
> This is my first post here - google hasn't helped much but sorry if this
> has been asked before.
> 
> I've been wondering about some of the technicalities of locks in python
> (2.4 and 2.5 mainly).
> 
> I'm using the "old" thread module as (1) I prefer the methods and (2) It
> should be a tiny bit faster.

You shouldn't use the thread module directly. It's not meant to be used
by a user. Please stick to the threading module. You won't notice a
slowdown, trust me :)

> As far as I can see, the thread module is fairly much a direct wrapper
> around "PyThread_allocate_lock" etc. - defined in
> "thread_pthread.h" (took me ages to find the definitions in a header
> file!), so as far as I can tell the implementation is very closely
> wrapped around the system's threading implementation. 

The header files Python/thread_*.h contain the interface to your
system's threading libraries. One of the files is included conditionally
depending on your OS.

> Does that mean that every python thread is actually a real separate
> thread (for some reason I thought they were implemented in the
> interpreter)?

Yes, Python uses native threads, not green threads. However Python pure
code can't utilize more than one CPU per process. On order to use
multiple CPUs you have to use multiple processes or use C code that
doesn't use any Python API. Google for "GIL" if you are interested in
more information.

> Does that also mean that there is very little extra interpreter-overhead
> to using locks (assuming they very infrequently block)? Since if you use
> the thread module direct the code doesn't seem to escape from C during
> the acquire() etc. or am I missing something important?

You are correct. The overhead is minimal.

Christian

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


Re: convert the ip packet to and from RS-232 packet

2009-02-09 Thread Jean-Paul Calderone

On Mon, 9 Feb 2009 05:13:10 -0800 (PST), Li Han  wrote:

Hi, I need to use radio to connect two local ip network, each local
network has a server computer which connects to a radio with RS-232
interface.  I need to write a program to convert the local ip packet
into RS-232 packet, so the radio can send packetes to the remote
radio. I don't want to reinvent the wheel, is there anyone could give
me some suggestions?


You can proxy between any two kinds of connection pretty easily with
Twisted (untested):

   from twisted.internet import serialport, protocol, reactor
   from twisted.protocols import portforward

   class SerialPortServer(portforward.Proxy):
   def connectionMade(self):
   # Stop the server, since only one thing can talk to the serial port
   # at a time.
   tcpPort.stopListening()

   # Hook up the proxy between this TCP connection and the serial port.
   self.peer = portforward.Proxy()
   self.peer.setPeer(self)
   self._serialPort = serialport.SerialPort(self.peer, '/dev/ttyS0', 
reactor)

   factory = protocol.ServerFactory()
   factory.protocol = SerialPortServer
   tcpPort = reactor.listenTCP(12345, factory)
   reactor.run()

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


version in setup.cfg

2009-02-09 Thread Jasiu
Hi guys,

I have a question about setup.py and setup.cfg:

I work in a company and we use Subversion to keep our stuff. We have a
post-commit rule that does the following: whenever there is a commit
to /tags/ directory, a binary package is built automatically. The
tag's name is the new version of the package, i.e. tag names are
something like /tags/1.5.2, /tags/1.2.3 etc. We use setup.py to create
packages. In setup.py we set the version of the package by specifying
'version' keyword argument to setup function. We have automated builds
and our post-commit script does kind of ugly regexp hack and replaces
string "version='...'" with version that is guessed from the tag name.
And I wonder: It would be much cleaner if the version could be placed
in the setup.cfg file. Is that possible?

Thanks,

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


Re: Py2app Py2exe and losing extensibility

2009-02-09 Thread Gabriel Genellina
En Mon, 09 Feb 2009 12:43:46 -0200, member Basu   
escribió:



I'm currently working on a project that allows users to write their own
Python modules as simple extensions (basically output formatters). I  
would
like to do a cross-platform release and so I'm using PyQt and will be  
trying
to convert it to native builds using Py2app and Py2xe. I don't want  
users to

have to install Qt and PyQt to run it. But if I do that, will I still be
able to load Python modules dynamically as extensions ? (assuming that  
the

user machine has Python installed separately).


I don't know about py2app but if you use py2exe your users still can  
provide their own modules. And they don't have to install Python  
separately (asuming that your "private" one contains all the library  
modules they want to use)

I don't understand your concerns about installing Qt/PyQt.

--
Gabriel Genellina

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


Re: Small socket problem

2009-02-09 Thread Jean-Paul Calderone

On Mon, 9 Feb 2009 09:43:36 +, John O'Hagan  wrote:

Hi,

I'm using the socket module (python 2.5) like this (where 'options' refers to
an optparse object) to connect to the Fluidsynth program:

   host = "localhost"
   port = 9800
   fluid = socket(AF_INET, SOCK_STREAM)
   try:
   fluid.connect((host, port))  #Connect if fluidsynth is running
   except BaseException:
   print "Connecting to fluidsynth..." #Or start fluidsynth
   soundfont =  options.soundfont
   driver = options.driver
   Popen(["fluidsynth", "-i", "-s", "-g", "0.5",
   "-C", "1",  "-R", "1", "-l", "-a", driver, "-j", soundfont])
   timeout = 50
   while 1:
   timeout -= 1
   if timeout == 0:
   print "Problem with fluidsynth: switching to synth."
   play_method = "synth"
   break
   try:
   fluid.connect((host, port))
   except BaseException:
   sleep(0.05)
   continue
   else:
   break

(I'm using BaseException because I haven't been able to discover what
exception class[es] socket uses).

The problem is that this fails to connect ( the error is "111: Connection
refused") the first time I run it after booting if fluidsynth is not already
running, no matter how long the timeout is; after Ctrl-C'ing out of the
program, all subsequent attempts succeed. Note that fluidsynth need not be
running for a success to occur.


The most obvious problem is that you're trying to re-use a socket on which
a connection attempt has failed.  This isn't allowed and will always fail.
You must create a new socket for each connection attempt.

You might also want to consider using a higher level socket library than
the "socket" module.  The socket module exposes you to lots of very low
level details and platform-specific idiosyncrasies.  You may find that a
library like Twisted () will let you write
programs with fewer bugs.

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


Re: thread. question

2009-02-09 Thread Tim Wintle
Thanks for both replies,

On Mon, 2009-02-09 at 15:59 +0100, Christian Heimes wrote:
> You shouldn't use the thread module directly. It's not meant to be used
> by a user. Please stick to the threading module. You won't notice a
> slowdown, trust me :)
I'm aware that thread is being renamed to _thread in python 3.0, but is
it being depricated or anything like that?

This is for an app that has been running for quite a long time and it's
now time for fairly heavy optimisations as load is increasing (Believe
me, I wouldn't have been looking at the C otherwise) - so I'll see if I
do notice any effect with threading.


> Yes, Python uses native threads, not green threads. However Python pure
> code can't utilize more than one CPU per process. On order to use
> multiple CPUs you have to use multiple processes or use C code that
> doesn't use any Python API. Google for "GIL" if you are interested in
> more information.

Thanks for the info - I'm very aware of the GIL, but had never looked at
the implementation before and for some reason thought that python's
threads were in userspace.

I'm already using a multiple-process architecture overall, but using
threads to avoid waiting when handling SQL and TCP.

Tim


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


Re: thread. question

2009-02-09 Thread Jean-Paul Calderone

On Mon, 09 Feb 2009 15:34:02 +, Tim Wintle  
wrote:

Thanks for both replies,

On Mon, 2009-02-09 at 15:59 +0100, Christian Heimes wrote:

You shouldn't use the thread module directly. It's not meant to be used
by a user. Please stick to the threading module. You won't notice a
slowdown, trust me :)

I'm aware that thread is being renamed to _thread in python 3.0, but is
it being depricated or anything like that?

This is for an app that has been running for quite a long time and it's
now time for fairly heavy optimisations as load is increasing (Believe
me, I wouldn't have been looking at the C otherwise) - so I'll see if I
do notice any effect with threading.


You may want to look into dropping the use of threads (where possible,
eg for handling TCP connections) if you're trying to optimize the app.
Threads come with a lot of overhead that can be avoided by using non-
blocking operations instead.

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


Re: cannot install

2009-02-09 Thread Benjamin Kaplan
On Mon, Feb 9, 2009 at 9:05 AM, Vladimír Župka  wrote:

> I have Mac OS X Leopard 10.5.6 and I downloaded and unpacked Python 3.0
> into a folder (/Library/Frameworks/Python.framework) and ran commands:
>
> cd /Library/Frameworks/Python.framework/Python-3.0
> python setup.py install
>
> and got the message reporting a syntax error:
>
> Macintosh:~ vzupka$ /bin/csh
> [Macintosh:~] vzupka% cd /Library/Frameworks/Python.framework/Python-3.0
> [Macintosh:Frameworks/Python.framework/Python-3.0] vzupka% python setup.py
> install
>   File "setup.py", line 232
> except (CCompilerError, DistutilsError) as why:
>  ^
> SyntaxError: invalid syntax
> [Macintosh:Frameworks/Python.framework/Python-3.0] vzupka%
>
> What is the reason and how do I install?
>


You can't use setup.py because the python 2.5 on your system (or 2.6 if you
installed it) is incompatible with Python 3 modules. You need to compile
Python 3 yourself. It will then automatically call setup.py to create all
the extension modules.

Just unpack the tarball anywhere and use the following commands  Python 3 is
automatically installed as python3.0, so you don't need to worry about
overwriting the default python on the system.

./configure --enable-framework
make
sudo make install

more complete instructions are in the Mac/README file, except substitute
"Python 3.0" everywhere it says "MacPython 2.6". You will probably need to
install a whole bunch of packages to compile it. configure will tell you
about them. MacPorts (www.macports.org) and fink (www.finkproject.org)
provide an easy way to get them.


> Regards,
> Vladimír Župka
> vzu...@volny.cz
>
>
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
--
http://mail.python.org/mailman/listinfo/python-list


Network packets processor advice

2009-02-09 Thread Krzysztof Retel
Hi,

I am wrting a network packet processor. The processor listens on a
specific port for incomming UDP or TCP packets. When the packet
arrives it has to parse it, store in DB and if this succeed it has to
acknowledge the packet to the client. Now the problem is that I want
to have a control over possible failures of the system. For instance,
if the DB is gone, the processor should stop working and restart when
DB is back to live.

So the questions are:
1. Which approach is the best for building such software? For instance
using threads?
2. I can use the 'monit' tool for monitorig processes. However, not
sure yet how to start a python script with a specific process id. Is
it possible at all?
3. Any other suggestions?

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


Re: Local python web server problem

2009-02-09 Thread Rob
> I run the cherrypy hello world! example and when I visit
> 127.0.0.1:8080
> on firefox, a nice "Hello World" appears. I am on ubuntu and my ip in
> local network is 192.168.100.18
> but when I visit 192.168.100.18, there is another page: "It Works!".
> What is "It Works!"? and when I type 192.168.100.18:8080 in another
> local pc, the page didn't load?

You need to have the server listen on 192.168.100.18 not 127.0.0.1. 
They are different.  127.0.0.1 is visible only locally. The
192.168.100.18 is visible both locally and from other hosts.

I don't use cherrypy so don't know how you set this up.  Are you using
apache to host cherrypy or does it have it's own web server? If your using
apache the IP address is selected with the Listen directive normally in
the /etc/apache2/ports.conf file.

> Thanks and sorry for my bad English.
Your english is good.

Rob

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


Re: easy_install

2009-02-09 Thread hall . jeff
I had it downloaded and sitting in the root c:\ but didn't get it to
run because I didn't think about the \scripts folder not being in the
Path. Problem solved and fixed. Thank you all for your help.

On a side note, "easy_install MySQL-python" produced the following
messages:
Searching for MySQL-python
Reading http://pypi.python.org/simple/MySQL_python/
Reading http://sourceforge.net/projects/mysql-python
Reading http://sourceforge.net/projects/mysql-python/
Best match: MySQL-python 1.2.3b1
Downloading 
http://osdn.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.3b1.tar.gz
Processing MySQL-python-1.2.3b1.tar.gz
Running MySQL-python-1.2.3b1\setup.py -q bdist_egg --dist-dir c:
\docume~1\jhall\locals~1\temp\easy_install-t_ph9k\MySQL-
python-1.2.3b1\egg-dist-tmp-3gtuz9
error: The system cannot find the file specified

installing from the hard drive worked fine, however.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Simple question - stock market simulation

2009-02-09 Thread Anthra Norell

cptn.spoon wrote:

I'm trying to create an incredibly simple stock market simulator to be
used in a childrens classroom and I'm wondering whether someone can
point me in the right direction.

I basically want to be able to have a stock struct as follows:

StockName = "Test"
StockPriceList = (12,13,12,10,10,8,10)
StockRisk = 0.15
StockQty = 2000

And then have a StockMarket struct that can contain 1 to many Stocks.
I then want to be able to iterate through the stocks to perform
operations as such:

for Stock in StockMarket:

I'm not asking for tips on the program itself, I just can't figure out
how to get the data structures in place. Would I use Classes or would
I use dictionaries? Am I completely off the mark with this?

Apologies for such a rudimentary question...I'm very new to all this.
--
http://mail.python.org/mailman/listinfo/python-list

  
If the subject is investment performance, surely your best bet is to 
hand out piggy banks.


Frederic





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


Re: programming by evolution?

2009-02-09 Thread Xah Lee
Xah Lee wrote:
> ...
> if you want software engineering books, i suggest try some books that
> are based on statistical survey, as opposed to some dignitary's
> “opinion” or current fashion & trends that comes with a jargon. These
> type of books are a dime a dozen, every year, they come and go. The
> stastical survey approach takes major understaking and cost. The
> opinion type any motherfucking “guru” can write. e.g. Paul Graham has
> you buy into certain concept of “hackers” fucker and claim they are
> like “painters”. Certain Gabriel wants you to believe in poetry and C
> is the last language. (see Book Review: Patterns of
> Software
> http://xahlee.org/PageTwo_dir/Personal_dir/bookReviewRichardGabriel.html
> ) et al. Certain Gosling wants you to believe Java is the last lang on
> earth that'll wipe out Microsoft (circa 1998).
>
> ...
>
> ... what society overwhelmingly asks for is snake oil. Of course, the
> snake oil has the most impressive names —otherwise you would be
> selling nothing— like “Structured Analysis and Design”, “Software
> Engineering”, “Maturity Models”, “Management Information Systems”,
> “Integrated Project Support Environments” “Object Orientation” and
> “Business Process Re-engineering” (the latter three being known as
> IPSE, OO and BPR, respectively).” — Edsger W Dijkstra (1930-2002), in
> EWD 1175: The strengths of the academic enterprise.
>
> you want to be a good programer? Study math, the math of programing,
> and master the langs and protocols and tools you use. You want to
> climb the tech industry ladder? get better at people, learn politics.
> You want to be rich? Study business. Chances are, you are a coding
> geek, and at heart you dna is not geared to be interested in politics
> or business, and you'll never be rich or big ceo just because of that.
>
> See also:
> • Why Software Suck
>  http://xahlee.org/UnixResource_dir/writ/why_software_suck.html
>
> looking at the eXtreme Programing fuckheads's traffic history:
> http://groups.google.com/group/comp.software.extreme-programming/about
>
> for those who are not aware, it was one of the snake oil wildly
> popular in around 2001.

Today, i happened to run across a blog on the eXtreme Programing FUCK.

http://www.yosefk.com/blog/extreme-programming-explained.html

Great article!

  Xah
∑ http://xahlee.org/

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


Re: Calling into Python from a C thread

2009-02-09 Thread Aahz
[posted & e-mailed]

In article ,
Philip Semanchuk   wrote:
>
>I'm trying call Python from inside of a C thread that's running in a  
>Python extension I've written and I am not having much luck. My C  
>thread function consists of simply this, and I get a segmentation  
>fault from Python:

Because it's been a week without response, I suggest you try the capi
mailing list.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote 
programs, then the first woodpecker that came along would destroy civilization.
--
http://mail.python.org/mailman/listinfo/python-list


GAE read binary file into db.BlobProperty()

2009-02-09 Thread alex goretoy
How to read Binary file into GAE(Google App Engine) db.BlobProperty()
datastore?

-Alex Goretoy
http://www.goretoy.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Flattening lists

2009-02-09 Thread ptn
On Feb 5, 2:07 pm, rdmur...@bitdance.com wrote:
> Quoth J Kenneth King :
>
>
>
> > mk  writes:
>
> > > Hello everybody,
>
> > > Any better solution than this?
>
> > > def flatten(x):
> > >     res = []
> > >     for el in x:
> > >         if isinstance(el,list):
> > >             res.extend(flatten(el))
> > >         else:
> > >             res.append(el)
> > >     return res
>
> > > a = [1, 2, 3, [4, 5, 6], [[7, 8], [9, 10]]]
> > > print flatten(a)
>
> > > [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>
> > > Regards,
> > > mk
>
> >http://mail.python.org/pipermail/python-list/2005-July/330367.html
>
> That's worth reading.  I'm not sure why I'm finding this fun, but who
> cares.  I tried a couple of other functions after reading that article,
> and it looks like a generator that scans the nested lists is actually
> the winner, and also is in many ways the most elegant implementation.
> Of course, as noted in the emails following above article, the test data
> is really inadequate for proper optimization testing ;)
>
> -
> from __future__ import print_function
> from timeit import Timer
> from itertools import chain
>
> # This is the one from the article quoted above.
> def flatten6(seq):
>     i = 0
>     while (i != len(seq)):
>         while hasattr(seq[i], '__iter__'):
>             seq[i:i+1] = seq[i]
>         i = i + 1
>     return seq
>
> #This is my favorite from a readability standpoint out of
> #all the things I tried.  It also performs the best.
> def flatten8(seq):
>     for x in seq:
>         if not hasattr(x, '__iter__'): yield x
>         else:
>             for y in flatten8(x):
>                 yield y
>
> l = [[1, 2, 3], 5, [7, 8], 3, [9, [10, 11, 12], 4, [9, [10, 5, 7]], 1, 
> [5, 4], 3], 4, 3], 3, 1, 45], 9], 10]]
>
> if __name__=="__main__":
>     print(l)
>     print('flatten6', flatten6(l))
>     print('flatten8', list(flatten8(l)))
>     print('flatten6', Timer("flatten6(l)", "from temp3 import flatten6, 
> l").timeit())
>     print('flatten8', Timer("list(flatten8(l))", "from temp3 import flatten8, 
> l").timeit())
>
> -
>
> >src/python/Python-3.0/python temp3.py
>
> [[1, 2, 3], 5, [7, 8], 3, [9, [10, 11, 12], 4, [9, [10, 5, 7]], 1, [5, 
> 4], 3], 4, 3], 3, 1, 45], 9], 10]]
> flatten6 [1, 2, 3, 5, 7, 8, 3, 9, 10, 11, 12, 4, 9, 10, 5, 7, 1, 5, 4, 3, 4, 
> 3, 3, 1, 45, 9, 10]
> flatten8 [1, 2, 3, 5, 7, 8, 3, 9, 10, 11, 12, 4, 9, 10, 5, 7, 1, 5, 4, 3, 4, 
> 3, 3, 1, 45, 9, 10]
> flatten6 32.8386368752
> flatten8 30.7509689331
>
> >python temp3.py
>
> [[1, 2, 3], 5, [7, 8], 3, [9, [10, 11, 12], 4, [9, [10, 5, 7]], 1, [5, 
> 4], 3], 4, 3], 3, 1, 45], 9], 10]]
> flatten6 [1, 2, 3, 5, 7, 8, 3, 9, 10, 11, 12, 4, 9, 10, 5, 7, 1, 5, 4, 3, 4, 
> 3, 3, 1, 45, 9, 10]
> flatten8 [1, 2, 3, 5, 7, 8, 3, 9, 10, 11, 12, 4, 9, 10, 5, 7, 1, 5, 4, 3, 4, 
> 3, 3, 1, 45, 9, 10]
> flatten6 34.730714798
> flatten8 32.3252940178
>
> --RDM

I think the generator is clearer with a try statement, like in Magnus
Lie Hetland's solution from Beginning Python:

def flatten(nested):
try:
# Don't iterate over string-like objs.
try: nested + ''
except TypeError: pass
else: raise TypeError
for sub in nested:
for elem in flatten(sub):
yield elem
except TypeError:
# The for doesn't work for single elements.
yield nested

You can't iterate over string-like objs because the all strings are
built of infinite empty lists at the beginning, leading to infinite
recursion.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Threading / Queue management

2009-02-09 Thread Aahz
In article ,
Power Button   wrote:
>
>I wonder if anyone can help with the following. I have written a
>script which polls a server and if it finds and pending orders, it
>instantiates an new object (foo) - in a new thread and processes some
>data. In the new object (foo), there are also some long running
>processes so I am trying to create a thread pool/queue and to push
>items onto the queue in the instantiated object (foo). Currently I am
>creating the Queue in foo but this means I am starting up 5 new
>threads every time I instantiate foo. What I want to be able to do is
>create the Queue and start 5 (n) threads when my program starts and
>then push items onto the queue in foo.

Not sure what you're trying to do, but you meay find this sample code
useful:

http://www.pythoncraft.com/OSCON2001/index.html
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote 
programs, then the first woodpecker that came along would destroy civilization.
--
http://mail.python.org/mailman/listinfo/python-list


Help needed to retrieve text from a text-file using RegEx

2009-02-09 Thread Oltmans
Here is the scenario:

It's a command line program. I ask user for a input string. Based on
that input string I retrieve text from a text file. My text file looks
like following

Text-file:
-
AbcManager=C:\source\code\Modules\Code-AbcManager\
AbcTest=C:\source\code\Modules\Code-AbcTest\
DecConnector=C:\source\code\Modules\Code-DecConnector\
GHIManager=C:\source\code\Modules\Code-GHIManager\
JKLConnector=C:\source\code\Modules\Code-JKLConnector

-

So now if I run the program and user enters

DecConnector

Then I'm supposed to show them this text "C:\source\code\Modules\Code-
DecConnector" from the text-file. Right now I'm retrieving using the
following code which seems quite ineffecient and inelegant at the same
time

 with open('MyTextFile.txt') as file:

for line in file:

if mName in line: #mName is the string that
contains user input

Path =str(line).strip('\n')

tempStr=Path

Path=tempStr.replace(mName+'=',"",1)

I was wondering if using RegEx will make this look better. If so, can
you please suggest a Regular Expression for this? Any help is highly
appreciated. Thank you.
--
http://mail.python.org/mailman/listinfo/python-list


Re: global name 'sqrt' is not defined

2009-02-09 Thread Rob
> Any ideas?  If I do something like "import math" in the subfunction, 
> then the error changes to "global name 'math' is not defined".

Presumably ipython does an import so you need to import it yourself
something like:

from math import sqrt

at the top of your source file.  I don't know why math would not be
defined, it's built in -- probably a scoping logic problem in your code. 
Put the form/import statement at the top of your module file (as is
usually done), not inside a function or other block.

Rob

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


Re: Calling into Python from a C thread

2009-02-09 Thread Philip Semanchuk


On Feb 9, 2009, at 12:02 PM, Aahz wrote:


[posted & e-mailed]

In article ,
Philip Semanchuk   wrote:


I'm trying call Python from inside of a C thread that's running in a
Python extension I've written and I am not having much luck. My C
thread function consists of simply this, and I get a segmentation
fault from Python:


Because it's been a week without response, I suggest you try the capi
mailing list.


I didn't know there *was* such a thing. Thanks for the tip! For those  
who might be interested, the list is here:

http://mail.python.org/mailman/listinfo/capi-sig


FYI, I got my code working and it is in the latest release of posix_ipc:
http://semanchuk.com/philip/posix_ipc/

The function MessageQueue_request_notification() does some necessary  
setup and the function process_notification() does the rest of the work.



Cheers
Philip


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


Re: wxPython vs Glade?

2009-02-09 Thread Bruno Desthuilliers

Michael Pobega a écrit :

I'm looking for opinions on the best toolkit for a beginner to use with
wxPython.



wxPython *is* a GUI toolkit (or, more exactly, a python binding for 
wxWidgets).



wxWidgets seems nice because it's portable, but I'm not sure how many of
my libraries are portable (a lot of them seem to import os),  while Glade
seems extremely simple to make a UI


Glade is a (graphical) GUI *builder* for the GTK+ toolkit - it' not a 
toolkit itself. So you're comparing apples to gorillas.


FWIW, there is (was ???) a Glade-like graphical builder for wxWidgets 
named wxGlade.



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


How to use buildout with a scripts directory?

2009-02-09 Thread Jon
Hello,

I am trying to use buildout and am having trouble to figure out how to
get it to install the scripts that come with a package. They are
present inside the egg which is installed by buildout, but they don't
end up in the bin directory. After running buildout my bin directory
is empty, but I can find:

.\eggs\imaged11-1.2.3-py2.5-win32.egg\EGG-INFO\scripts\peaksearch.py

In the package I have a directory (ImageD11) with the library stuff in
it and a directory named "scripts" with the scripts. When I use
distutils or setuptools it does what I expected:

setup.py:
...
setup(name='ImageD11',
  ...,
  packages = ["ImageD11"],
  package_dir = {"ImageD11":"ImageD11"},
 scripts = [ "scripts/peaksearch.py",
"scripts/bgmaker.py",
...]
 )



c:\testImageD11distutils\> python setup.py install
...
Installing peaksearch.py script to c:\python25\Scripts
Installing bgmaker.py script to c:\python25\Scripts

Now I am wondering how to persuade "buildout" to do the same thing,
but place those scripts into it's own little area.

In buildout.cfg I have:
==
[buildout]
parts = ImageD11

[ImageD11]
recipe = zc.recipe.egg:scripts
scripts = scripts/peaksearch.py
eggs = ImageD11
version = 1.2.3


It seems to acknowledge that scripts/peaksearch.py is requested, but
doesn't seem to do anything about it. My scripts mostly just map
command line arguments to function calls, something like this:

if __name__=="__main__":
import ImageD11.something, sys
ImageD11.something.do_something_interesting( sys.argv[1], sys.argv
[2] )

I've read the documentation at http://pypi.python.org/pypi/zc.buildout
several times but I still can't figure out how to make these scripts
part of the build. There seems to be a lot of talk about entry_points,
but I'm blocked on those as to what is the entry point for an if
__name__=="__main__": idiom?

Thanks in advance for any help!

Jon



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


Re: Help needed to retrieve text from a text-file using RegEx

2009-02-09 Thread Chris Rebert
On Mon, Feb 9, 2009 at 9:22 AM, Oltmans  wrote:
> Here is the scenario:
>
> It's a command line program. I ask user for a input string. Based on
> that input string I retrieve text from a text file. My text file looks
> like following
>
> Text-file:
> -
> AbcManager=C:\source\code\Modules\Code-AbcManager\
> AbcTest=C:\source\code\Modules\Code-AbcTest\
> DecConnector=C:\source\code\Modules\Code-DecConnector\
> GHIManager=C:\source\code\Modules\Code-GHIManager\
> JKLConnector=C:\source\code\Modules\Code-JKLConnector
>
> -
>
> So now if I run the program and user enters
>
> DecConnector
>
> Then I'm supposed to show them this text "C:\source\code\Modules\Code-
> DecConnector" from the text-file. Right now I'm retrieving using the
> following code which seems quite ineffecient and inelegant at the same
> time
>
>  with open('MyTextFile.txt') as file:
>
>for line in file:
>
>if mName in line: #mName is the string that
> contains user input
>
>Path =str(line).strip('\n')
>
>tempStr=Path
>
>Path=tempStr.replace(mName+'=',"",1)
>
> I was wondering if using RegEx will make this look better. If so, can
> you please suggest a Regular Expression for this? Any help is highly
> appreciated. Thank you.

If I might repeat Jamie Zawinski's immortal quote:
Some people, when confronted with a problem, think "I know, I'll
use regular expressions." Now they have two problems.

If you add one section header (e.g. "[main]") to the top of the file,
you'll have a valid INI-format file which can be parsed by the
ConfigParser module --
http://docs.python.org/library/configparser.html

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


generator object or 'send' method?

2009-02-09 Thread Aaron Brady
Hello,

I am writing a generator to return a sequence of numbers with some
variation.  The parameters of the variation can be changed by the
caller, even after the generator is started.  My question is, is it
better to wrap the generator in an object, so that the parameters can
be changed just by an attribute access?  Or keep the generator clear,
and modify parameters with a 'send' call?

P.S.  It would receive the 'send' from a different point in control
flow than its usual 'next'.  Should it repeat a value if it receives a
'send'?  Or should I wrap it in a secondary 'trap_send_and_repeat'
generator?

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


Putting asterisks around text

2009-02-09 Thread todp...@hotmail.com

I'm trying to write a program that puts asterisks around the input text using 
while loop.
I can do this without using while loop, but how can you do that using while 
loop?Example:Enter a string: Hello world***Hello world***
_
So many new options, so little time. Windows Live Messenger.
http://www.microsoft.com/windows/windowslive/messenger.aspx--
http://mail.python.org/mailman/listinfo/python-list


Re: Help needed to retrieve text from a text-file using RegEx

2009-02-09 Thread Bruno Desthuilliers

Oltmans a écrit :

Here is the scenario:

It's a command line program. I ask user for a input string. Based on
that input string I retrieve text from a text file. My text file looks
like following

Text-file:
-
AbcManager=C:\source\code\Modules\Code-AbcManager\
AbcTest=C:\source\code\Modules\Code-AbcTest\
DecConnector=C:\source\code\Modules\Code-DecConnector\
GHIManager=C:\source\code\Modules\Code-GHIManager\
JKLConnector=C:\source\code\Modules\Code-JKLConnector

-

So now if I run the program and user enters

DecConnector

Then I'm supposed to show them this text "C:\source\code\Modules\Code-
DecConnector" from the text-file. Right now I'm retrieving using the
following code which seems quite ineffecient and inelegant at the same
time

 with open('MyTextFile.txt') 


This will lookup for MyFile.txt in the system's current working 
directory - which is not necessarily in the script's directory.



 as file:


this shadows the builtin's 'file' symbol.


for line in file:

if mName in line: #mName is the string that
contains user input




Path =str(line).strip('\n')


'line' is already a string.


tempStr=Path

Path=tempStr.replace(mName+'=',"",1)


You don't need the temporary variable here. Also, you may want to use 
str.split instead:



# NB : renaming for conformity to
# Python's official naming conventions

# 'name' => what the user looks for
# 'path_to_file' => fully qualified path to the 'database' file

target = "%s=" % name # what we are really looking for

with open(path_to_file) as the_file:
for line in the_file:
# special bonus : handles empty lines and 'comment' lines
# feel free to comment out the thre following lines if
# you're sure you don't need them !-)
line = line.strip()
if not line or line.startswith('#') or line.startswith(';'):
continue

# faster and simpler than a regexp
if line.startswith(target):
# since the '=' is in target, we can safely assume
# that line.split('=') will return at least a
# 2-elements list
path = line.split('=')[1]
# no need to look further
break
else:
# target not found...
path = None




I was wondering if using RegEx will make this look better.


I don't think so. Really.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Putting asterisks around text

2009-02-09 Thread D'Arcy J.M. Cain
On Mon, 9 Feb 2009 10:09:26 -0800
"todp...@hotmail.com"  wrote:
> I'm trying to write a program that puts asterisks around the input text using 
> while loop.
> I can do this without using while loop, but how can you do that using while 
> loop?Example:Enter a string: Hello world***Hello world***

while understand_problem is False:
study("textbook")

complete("homework")

if want_help is True:
study("http://www.catb.org/~esr/faqs/smart-questions.html";)

-- 
D'Arcy J.M. Cain  |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Putting asterisks around text

2009-02-09 Thread MRAB

D'Arcy J.M. Cain wrote:

On Mon, 9 Feb 2009 10:09:26 -0800
"todp...@hotmail.com"  wrote:

I'm trying to write a program that puts asterisks around the input text using 
while loop.
I can do this without using while loop, but how can you do that using while 
loop?Example:Enter a string: Hello world***Hello world***


while understand_problem is False:
study("textbook")

complete("homework")

if want_help is True:
study("http://www.catb.org/~esr/faqs/smart-questions.html";)


That's not Pythonic, and you shouldn't use "is" except when checking for
identity. The recommended style is:

while not understand_problem:
study("textbook")

complete("homework")

if want_help:
study("http://www.catb.org/~esr/faqs/smart-questions.html";)

See how much clearer that is? ;-)
--
http://mail.python.org/mailman/listinfo/python-list


Help needed to retrieve text from a text-file using RegEx

2009-02-09 Thread rdmurray
Oltmans  wrote:
> Here is the scenario:
> 
> It's a command line program. I ask user for a input string. Based on
> that input string I retrieve text from a text file. My text file looks
> like following
> 
> Text-file:
> -
> AbcManager=C:\source\code\Modules\Code-AbcManager\
> AbcTest=C:\source\code\Modules\Code-AbcTest\
> DecConnector=C:\source\code\Modules\Code-DecConnector\
> GHIManager=C:\source\code\Modules\Code-GHIManager\
> JKLConnector=C:\source\code\Modules\Code-JKLConnector
> 
> -
> 
> So now if I run the program and user enters
> 
> DecConnector
> 
> Then I'm supposed to show them this text "C:\source\code\Modules\Code-
> DecConnector" from the text-file. Right now I'm retrieving using the
> following code which seems quite ineffecient and inelegant at the same
> time
> 
>  with open('MyTextFile.txt') as file:
>  for line in file:
>  if mName in line: #mName is the string that contains user input
>  Path =str(line).strip('\n')
>  tempStr=Path
>  Path=tempStr.replace(mName+'=',"",1)

I've normalized your indentation and spacing, for clarity.

> I was wondering if using RegEx will make this look better. If so, can
> you please suggest a Regular Expression for this? Any help is highly
> appreciated. Thank you.

This smells like it might be homework, but I'm hoping you'll learn some
useful python from what follows regardless of whether it is or not.

Since your complaint is that the above code is inelegant and inefficient,
let's clean it up.  The first three lines that open the file and set up
your loop are good, and I think you will agree that they are pretty clean.
So, I'm just going to help you clean up the loop body.

'line' is already a string, since it was read from a file.  No need to
wrap it in 'str':

  Path = line.strip('\n')
  tempStr=Path
  Path=tempStr.replace(mName+'=',"",1)

'strip' removes characters from _both_ ends of the string.  If you are
trying to make sure that you _only_ strip a trailing newline, then you
should be using rstrip.  If, on the other hand, you just want to get
rid of any leading or trailing whitespace, you could just call 'strip()'.
Since your goal is to print the text from after the '=', I'll assume
that stripping whitespace is desirable:

  Path = line.strip()
  tempStr=Path
  Path=tempStr.replace(mName+'=',"",1)

The statement 'tempStr=Path' doesn't do what you think it does.
It just creates an alternate name for the string pointed to by Path.
Further, there is no need to have an intermediate variable to hold a
value during transformation.  The right hand side is computed, using
the current values of any variables mentioned, and _then_ the left hand
side is rebound to point to the result of the computation.  So we can
just drop that line entirely, and use 'Path' in the 'replace' statement:

  Path = line.strip()
  Path = Path.replace(mName+'=',"",1)

However, you can also chain method calls, so really there's no need for
two statements here, since both calls are simple:

  Path = line.strip().replace(mName+'=',"",1)

To make things even simpler, Python has a 'split' function.  Given the
syntax of your input file I think we can assume that '=' never appears
in a variable name.  split returns a list of strings constructed by
breaking the input string at the split character, and it has an optional
argument that gives the maximum number of splits to make.  So by doing
'split('=', 1), we will get back a list consisting of the variable name
and the remainder of the line.  The remainder of the line is exactly
what you are looking for, and that will be the second element of the
returned list.  So now your loop body is:

  Path = line.strip().split('=', 1)[1]

and your whole loop looks like this:

with open('MyTextFile.txt') as file:
for line in file:
if mName in line:
Path = line.strip().split('=', 1)[1]

I think that looks pretty elegant.  Oh, and you might want to add a
'break' statement to the loop, and also an 'else:' clause (to the for
loop) so you can issue a 'not found' message to the user if they type
in a name that does not appear in the input file.

--RDM

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


Re: Help needed to retrieve text from a text-file using RegEx

2009-02-09 Thread Paul McGuire
On Feb 9, 11:22 am, Oltmans  wrote:
> Here is the scenario:
>
> It's a command line program. I ask user for a input string. Based on
> that input string I retrieve text from a text file. My text file looks
> like following
>
> Text-file:
> -
> AbcManager=C:\source\code\Modules\Code-AbcManager\
> AbcTest=C:\source\code\Modules\Code-AbcTest\
> DecConnector=C:\source\code\Modules\Code-DecConnector\
> GHIManager=C:\source\code\Modules\Code-GHIManager\
> JKLConnector=C:\source\code\Modules\Code-JKLConnector
>

Assuming the text-file is in the under-30Mb size, I would just read
the whole thing into a dict at startup, and then use the dict over and
over.

data = file(filename).read()
lookup = dict( line.split('=',1) for line in data.splitlines() if
line )

# now no further need to access text file, just use lookup variable

while True:
user_entry = raw_input("Lookup key: ").strip()
if not user_entry:
break
if user_entry in lookup:
print lookup[user_entry]
else:
print "No entry for '%s'" % user_entry
--
http://mail.python.org/mailman/listinfo/python-list


RE: Putting asterisks around text

2009-02-09 Thread todp...@hotmail.com



From: todp...@hotmail.comto: python-l...@python.orgsubject: Putting asterisks 
around textDate: Mon, 9 Feb 2009 10:09:26 -0800

I'm trying to write a program that puts asterisks around the input text using 
while loop.I can do this without using while loop, but how can you do that 
using while loop?Example:Enter a string: Hello world***Hello 
world***
 
I'm not necessarily asking for an answer. A hint would be grateful as well.
_
So many new options, so little time. Windows Live Messenger.
http://www.microsoft.com/windows/windowslive/messenger.aspx--
http://mail.python.org/mailman/listinfo/python-list


Re: Putting asterisks around text

2009-02-09 Thread Tim Rowe
2009/2/9 todp...@hotmail.com :

> I'm not necessarily asking for an answer. A hint would be grateful as well.

Great. Well, first you need to read:
http://www.catb.org/~esr/faqs/smart-questions.html

Especially the section on "Before you ask".

Then you should be able to give us a question that shows that you've
tried and aren't just wanting us to do your work for you, and that
gives us a clear idea of where your sticking point is so we can
address the sticking point instead of the whole assignment.

Like: How fo you do it without using a while loop? (Yes, *I* know how
to do it without using a while loop, but to help you we need to know
what *you* know). Like: do you understand what a while loop does? And
so on.

We're a pretty friendly bunch in here, but most of us believe in
"tough love" (http://en.wikipedia.org/wiki/Tough_love).

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


Re: Putting asterisks around text

2009-02-09 Thread Tim Chase

D'Arcy J.M. Cain wrote:

On Mon, 9 Feb 2009 10:09:26 -0800
"todp...@hotmail.com"  wrote:

I'm trying to write a program that puts asterisks around the
input text using while loop.
I can do this without using while loop, but how can you do
that using while loop?
Example:Enter a string: Hello world***Hello world***


while understand_problem is False:
study("textbook")
complete("homework")


This implies global state is changed, and that it holds a literal 
False rather than a False-ish value.  It also doesn't make _good_ 
use of c.l.p so I'd recommend


  smart_qs = "http://www.catb.org/~esr/faqs/smart-questions.html";
  todpose = Newb()
  todpose.study(textbook)
  code = todpose.make_coding_attempt()
  works = test(code)
  while not (todpose.understand_problem() and works):
if works:
  todpose.study([code, textbook])
else:
  try:
while not passes(todpose.question, smart_qs):
  todpose.study([
smart_qs,
textbook,
"www.google.com",
"docs.python.org",
])
# Note:  consult_clp() expects a valid
# code object and a smart-question
consult_clp(code, todpose.question)
  except EpiphanyException:
code = todpose.make_coding_attempt()
works = test(code)
continue
  todpose.hand_in(teacher, code)

-tkc






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


Re: generator object or 'send' method?

2009-02-09 Thread Terry Reedy

Aaron Brady wrote:

Hello,

I am writing a generator to return a sequence of numbers with some
variation.  The parameters of the variation can be changed by the
caller, even after the generator is started.  My question is, is it
better to wrap the generator in an object, so that the parameters can
be changed just by an attribute access?


Rather than wrap a generator, I would just write an iterator class.
A generator function is basically an abbreviated class statement.  (The 
abbreviation is the removal of boilerplate code.)


> Or keep the generator clear, and modify parameters with a 'send' call?

If I were modifying a single parameter and wanted the next value 
returned immediately upon sending, I would do this.



P.S.  It would receive the 'send' from a different point in control
flow than its usual 'next'.  Should it repeat a value if it receives a
'send'?  Or should I wrap it in a secondary 'trap_send_and_repeat'
generator?


But for this I would go with the class.  Pretty foolproof.

tjr

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


Re: wxPython vs Glade?

2009-02-09 Thread Stef Mientki

Michael Pobega wrote:

I'm looking for opinions on the best toolkit for a beginner to use with
wxPython. It doesn't necessarily need to be the most efficient toolkit,
but something I can use for basic programs (a Twitter client, Wordpress
blogging client, etc) just to learn Python.

wxWidgets seems nice because it's portable, but I'm not sure how many of
my libraries are portable (a lot of them seem to import os), while Glade
seems extremely simple to make a UI (but does the program end up relying
on Glade? Or can I build it directly into GTK+?)

  

there's XRC and something even easier:
http://mientki.ruhosting.nl/data_www/pylab_works/pw_gui_support.html
cheers,
Stef

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


Re: Best 3d graphics kit for CAD program???

2009-02-09 Thread Stef Mientki

Gary Herron wrote:

rantingrick wrote:

I want to build a 3D CAD visualization program with Python. Now before
you say this is not possible with Python here me out :)

I know OpenGL is probably my best bet BUT i want something a little
higher level than that. I am not ready for OpenGL yet.  I would like a
kit that is just above OpenGL and abstracts away all the finer
details, but not too much higher. VPython is a great kit but it is way
too high level for what i want. Here is a list of kits i am currently
looking at so if anybody can offer suggestions i would very much like
the information. Most of these are dedicated game engines but this is
all i can find

Panda 3D
OGRE
Soya 3D
VTK
Cystal Space
CG Kit
SciPy
  



Maya ?
Blender ?

cheers,
Stef

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


Re: Best 3d graphics kit for CAD program???

2009-02-09 Thread Stef Mientki

Gary Herron wrote:

rantingrick wrote:

I want to build a 3D CAD visualization program with Python. Now before
you say this is not possible with Python here me out :)

I know OpenGL is probably my best bet BUT i want something a little
higher level than that. I am not ready for OpenGL yet.  I would like a
kit that is just above OpenGL and abstracts away all the finer
details, but not too much higher. VPython is a great kit but it is way
too high level for what i want. Here is a list of kits i am currently
looking at so if anybody can offer suggestions i would very much like
the information. Most of these are dedicated game engines but this is
all i can find

Panda 3D
OGRE
Soya 3D
VTK
Cystal Space
CG Kit
SciPy
  



I forgot:
pySoy
Intensity

cheers,
Stef

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


Re: Calling into Python from a C thread

2009-02-09 Thread Christian Heimes
Philip Semanchuk wrote:
> I didn't know there *was* such a thing. Thanks for the tip! For those
> who might be interested, the list is here:
> http://mail.python.org/mailman/listinfo/capi-sig
> 
> 
> FYI, I got my code working and it is in the latest release of posix_ipc:
> http://semanchuk.com/philip/posix_ipc/
> 
> The function MessageQueue_request_notification() does some necessary
> setup and the function process_notification() does the rest of the work.

Let me guess. You either forgot to start Python's threading system or
you didn't register you thread with Python. You need to deal with
PyThread_init_thread(), PyEval_InitThreads(), PyThreadState_New(),
PyThreadState_Clear() and PyThreadState_DeleteCurrent(). The module
Modules/threadmodule.c contains some examples.

Christian

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


Re: wxPython vs Glade?

2009-02-09 Thread Mike Driscoll
On Feb 9, 7:23 am, Michael Pobega  wrote:
> I'm looking for opinions on the best toolkit for a beginner to use with
> wxPython. It doesn't necessarily need to be the most efficient toolkit,
> but something I can use for basic programs (a Twitter client, Wordpress
> blogging client, etc) just to learn Python.
>
> wxWidgets seems nice because it's portable, but I'm not sure how many of
> my libraries are portable (a lot of them seem to import os), while Glade
> seems extremely simple to make a UI (but does the program end up relying
> on Glade? Or can I build it directly into GTK+?)
>
> --
>                  http://pobega.wordpress.com
>                    http://identica/pobega
>
>  signature.asc
> < 1KViewDownload

I usually just hand-code my apps in IDLE or Wing IDE. I recommend
joining the official wxPython mailing list regardless of what you pick
though as you'll likely pick up a LOT of helpful tips and tricks
there.

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


Re: py2exe and distutils

2009-02-09 Thread Maxim Demenko

Gabriel Genellina schrieb:
En Sat, 07 Feb 2009 18:39:19 -0200, Thomas Heller  
escribió:



Maxim Demenko schrieb:

Hi,
i have installed Python 2.5.4 on WinXP, setuptools-0.6c9 and py2exe 
0.6.9

Now i can't list installed modules, here is the stacktrace:

[...]

Any suggestion, how to fix this issue?



Thomas Heller schrieb:

Looks like a setuptools problem to me.  Here's the output on my system:


Actually, I don't know where the problem is.  Maybe pydoc?


Yes, pydoc isn't robust enough in 2.5; see 
 
for a quick fix.




Thank you Gabriel, that works nicely.

Best regards

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


Re: version in setup.cfg

2009-02-09 Thread Diez B. Roggisch

Jasiu schrieb:

Hi guys,

I have a question about setup.py and setup.cfg:

I work in a company and we use Subversion to keep our stuff. We have a
post-commit rule that does the following: whenever there is a commit
to /tags/ directory, a binary package is built automatically. The
tag's name is the new version of the package, i.e. tag names are
something like /tags/1.5.2, /tags/1.2.3 etc. We use setup.py to create
packages. In setup.py we set the version of the package by specifying
'version' keyword argument to setup function. We have automated builds
and our post-commit script does kind of ugly regexp hack and replaces
string "version='...'" with version that is guessed from the tag name.
And I wonder: It would be much cleaner if the version could be placed
in the setup.cfg file. Is that possible?


I don't think so. But there are several other options:

 - install pysvn & use that in setup.py to extract the tag from the 
working-copy, making it part of version


 - instead of the dirty hack, use an a little bit less ugly hack to 
write that version to a file in the WC, and open & read that within setup.py


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


Re: thread. question

2009-02-09 Thread Christian Heimes
Tim Wintle schrieb:
> Thanks for both replies,
> 
> On Mon, 2009-02-09 at 15:59 +0100, Christian Heimes wrote:
>> You shouldn't use the thread module directly. It's not meant to be used
>> by a user. Please stick to the threading module. You won't notice a
>> slowdown, trust me :)
> I'm aware that thread is being renamed to _thread in python 3.0, but is
> it being depricated or anything like that?
> 
> This is for an app that has been running for quite a long time and it's
> now time for fairly heavy optimisations as load is increasing (Believe
> me, I wouldn't have been looking at the C otherwise) - so I'll see if I
> do notice any effect with threading.

[snip]

> Thanks for the info - I'm very aware of the GIL, but had never looked at
> the implementation before and for some reason thought that python's
> threads were in userspace.
> 
> I'm already using a multiple-process architecture overall, but using
> threads to avoid waiting when handling SQL and TCP.

The module was renamed to _thread to stop people from using it directly.
The extension module is the interface to some low level types and
functions. Especially the usage of thread.start_new_thread is
problematic, since it bypasses Python's high level threading API.

For the rest I have to agree with Jean-Paul. If you need performance
don't use threads! Threads and performance are orthogonal -- sometimes
they are even contradictorily.

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


Re: generator object or 'send' method?

2009-02-09 Thread andrew cooke

If I were experimenting with Python to see just how far I could push
coroutines at the moment, I would use .send() and look at how I could
factor things into a small library (containing, for example, your
trap-and-response secondary generator).

But if this was paid work, I would write a class with a __next__ method
and do things explicitly.

In answer to your PS, via a roundabout route: I've done something similar
recently by using .throw() to raise an exception in the body of the
generator.  This was done with a reset() function.  So, for example:

  mygen = ...
  a = next(mygen)
  b = next(mygen)
  reset(mygen)
  c = next(mygen)

And in the generator:

  while True:
try:
  ...
  yield ...
catch ResetException:
  yield # discarded by the reset function

And finally:

  def reset(gen):
gen.throw(ResetException())

In that case, I needed an extra "yield" that did nothing.

Andrew


Aaron Brady wrote:
> Hello,
>
> I am writing a generator to return a sequence of numbers with some
> variation.  The parameters of the variation can be changed by the
> caller, even after the generator is started.  My question is, is it
> better to wrap the generator in an object, so that the parameters can
> be changed just by an attribute access?  Or keep the generator clear,
> and modify parameters with a 'send' call?
>
> P.S.  It would receive the 'send' from a different point in control
> flow than its usual 'next'.  Should it repeat a value if it receives a
> 'send'?  Or should I wrap it in a secondary 'trap_send_and_repeat'
> generator?
>
> Thanks sincerely as always.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


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


Re: Best 3d graphics kit for CAD program???

2009-02-09 Thread r
On Feb 9, 1:33 pm, Stef Mientki  wrote:

> Maya ?
> Blender ?

> I forgot:
> pySoy
> Intensity

Thanks Stef,
I actually got OpenGL to install(finally) and now i am thinking ?
maybe? i should just go with OpenGL using the wxglcanvas. I have been
also "messing" around with Bender but i think i want a stand alone
application here. I don't know anything about Maya however?

Thanks for the info and feel free to offer more.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Calling into Python from a C thread

2009-02-09 Thread Philip Semanchuk


On Feb 9, 2009, at 2:35 PM, Christian Heimes wrote:


Philip Semanchuk wrote:

I didn't know there *was* such a thing. Thanks for the tip! For those
who might be interested, the list is here:
http://mail.python.org/mailman/listinfo/capi-sig


FYI, I got my code working and it is in the latest release of  
posix_ipc:

http://semanchuk.com/philip/posix_ipc/

The function MessageQueue_request_notification() does some necessary
setup and the function process_notification() does the rest of the  
work.


Let me guess. You either forgot to start Python's threading system or
you didn't register you thread with Python. You need to deal with
PyThread_init_thread(), PyEval_InitThreads(), PyThreadState_New(),
PyThreadState_Clear() and PyThreadState_DeleteCurrent(). The module
Modules/threadmodule.c contains some examples.


Yes, that's accurate except for the word "forgot". To forget something  
one must first know it. =) I found the threading API documentation  
difficult to follow, but I suppose that what I'm doing is a little  
unusual so if it is not well-documented territory, that's what I get  
for wandering off the map.



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


compound regex

2009-02-09 Thread spir
Hello,

(new here)

Below an extension to standard module re. The point is to allow writing and 
testing sub-expressions individually, then nest them into a super-expression. 
More or less like using a parser generator -- but keeping regex grammar and 
power.
I used the format {sub_expr_name}: as in standard regexes {} are only used to 
express repetition number, a pair of curly braces nesting an identifier should 
not conflict.

The extension is new, very few tested. I would enjoy comments, critics, etc. I 
would like to know if you find such a feature useful. You will probably find 
the code simple enough ;-) 

Denis
--
la vida e estranya

===
# coding: utf-8

''' super_regex

Define & check sub-patterns individually,
then include them in global super-pattern.

uses format {name} for inclusion:
sub1 = Regex(...)
sub2 = Regex(...)
super_format = "...{sub1}...{sub2}..."
# final regex object:
super_regex = superRegex(super_format)
'''

from re import compile as Regex

# sub-pattern inclusion format
sub_pattern = Regex(r"{[a-zA-Z_][a-zA-Z_0-9]*}")

# sub-pattern expander
def sub_pattern_expansion(inclusion, dic=None):
name = inclusion.group()[1:-1]
### namespace dict may be specified -- else globals()
if dic is None:
dic = globals()
if name not in dic:
raise NameError("Cannot find sub-pattern '%s'." % name)
return dic[name].pattern

# super-pattern generator
def superRegex(format):
expanded_format = sub_pattern.sub(sub_pattern_expansion, format)
return Regex(expanded_format)

if __name__ == "__main__": # purely artificial example use
# pattern
time = Regex(r"\d\d:\d\d:\d\d") # hh:mm:ss
code = Regex(r"\S{5}")  # non-whitespace x 5
desc = Regex(r"[\w\s]+$")   # alphanum|space --> EOL
ref_format = "^ref: {time} #{code} --- {desc}"
ref_regex = superRegex(ref_format)
# output
print 'super pattern:\n"%s" ==>\n"%s"\n' % 
(ref_format,ref_regex.pattern)
text = "ref: 12:04:59 #%+.?% --- foo 987 bar"
result = ref_regex.match(text)
print 'text: "%s" ==>\n"%s"' %(text,result.group())
--
http://mail.python.org/mailman/listinfo/python-list


problem with import path on a python C extension

2009-02-09 Thread fredbasset1000
Hi All,

I've written a simple Python extension module in C, but Python is
having problems trying to locate it when I import it into an existing
Python file.  In my example, I wrote a C extension called "diomodule"
which exists in the directory : /root/project/drivers/dio/
diomodule.c.  It has compiled fine and I end up with a diomodule.so
file in that same directory.  I have problems when trying to import it
into another Python file however, e.g. in a file /root/project/daemon/
daemon.py I tried to import it with "import
project.drivers.dio.diomodule".  Python throws an error however when I
try to call one of the functions:

  File "/root/project/daemon/daemon.py", line 115,
in ?
diomodule.init
()
NameError: name 'diomodule' is not defined

I can only get it to work if I copy the .so file to the directory
where daemon.py is and change the import to "import diomodule".

So my question is why can't Python locate the new extension module
when I try to import it with "import project.drivers.dio.diomodule"?

Thanks for any responses,
Fred
--
http://mail.python.org/mailman/listinfo/python-list


Re: Calling into Python from a C thread

2009-02-09 Thread Christian Heimes
Philip Semanchuk wrote:
> Yes, that's accurate except for the word "forgot". To forget something
> one must first know it. =) I found the threading API documentation
> difficult to follow, but I suppose that what I'm doing is a little
> unusual so if it is not well-documented territory, that's what I get for
> wandering off the map.

I see. Apparently the threading and embedding docs don't cover your
case. The docs at
http://docs.python.org/c-api/init.html#thread-state-and-the-global-interpreter-lock
and http://docs.python.org/extending/embedding.html should explain how
and when to initialize Python threads. Please report a documentation bug
at http://bugs.python.org/.

Christian

PS: I know a great way to learn more about Python's internal threading
CAPI: fix your code, test it and attach a doc patch to your bug report.
*hint* :)

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


Python 3D CAD -- need collaborators, or just brave souls :)

2009-02-09 Thread rantingrick
Hello all,

It has long been my dream to create an open source 3D CAD program and
i am starting to crawl my way into the first steps. I now believe i am
ready to start this endeavor and i am currently looking for fellow
Python programmers (no matter what skill level) to get started
brainstorming this design.

I have a real good idea of the UI design and at this point i just want
to start simple and build this thing. I figure this will be a good
learning experience for myself and others and in the process i can
realize my dream. And if all this turns out to be is a learning
experience, well nobody lost.

Of course Python will limit the speed here, but at this point i want
to get a template up and running. Speed does not matter at this point,
and optimizations can come along later as i am sure a few complete re-
writes are inevitable :)

My initial start will cover a very simple user interface something
like VPython but much more usable as a CAD modeler. From the start
just a few simple primitives (faces, lines-segments) that will be the
building blocks for more complex models like (arcs, rectangles,
circles, polygons, cubes, spheres, etc..).

There will need to be mouse picking as i see this application as a
very interactive environment. Of course in the beginning all
interaction will most likely be in a command line type manner until
the functionality can be worked out.

There will need to be a hierarchy of instancing and grouping within
the model to facilitate easy transformation of entities within the
model.

I am not too worried about any sort of texturing at this point. I want
to squeeze as much speed as possible and prettiness will come in due
course. I also have no plans for layering, or multiple scenes at this
time. Simple functionality is the end game here.

Once the UI is there and the modeling work flow is worked out,
everything should be a component add-on from there.

So the main points are...

#-- Entities --#
 face
 line-segment

#-- Hierarchy --#
 Entity (one face, or line-segment)
 Group (contained of multiple entities that can be translated,
rotated, scaled as one)
 Instance (component definition)

#-- Tools --#
 line
 rect
 circle
 arc
 select
 rotation
 translation
 scale
 extrusion along path
 measurement


So there it is. Any takers? :)


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


Re: problem with import path on a python C extension

2009-02-09 Thread Carsten Haese
fredbasset1...@gmail.com wrote:
> [...]
> So my question is why can't Python locate the new extension module
> when I try to import it with "import project.drivers.dio.diomodule"?
This import statement binds the module to the name
"project.drivers.dio.diomodule". It does not bind anything to the name
"diomodule", which is the name you want to use to refer to the module.

To bind the "diomodule" name to this module, you can do one of two things:

1:
   from project.drivers.dio import diomodule

2:
   import project.drivers.dio.diomodule
   diomodule = project.drivers.dio.diomodule

Hope this helps,

--
Carsten Haese
http://informixdb.sourceforge.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: problem with import path on a python C extension

2009-02-09 Thread Carsten Haese
fredbasset1...@gmail.com wrote:
> I can only get it to work if I copy the .so file to the directory
> where daemon.py is and change the import to "import diomodule".

And to supplement my previous reply, another solution is to make sure
that /root/project/drivers/dio is in your PYTHONPATH. Then you can
simply "import diomodule" and refer to the module by the name "diomodule".

HTH,

--
Carsten Haese
http://informixdb.sourceforge.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Putting asterisks around text

2009-02-09 Thread Martin
Hi,

2009/2/9 todp...@hotmail.com :
> I'm trying to write a program that puts asterisks around the input text
> using while loop.
> I can do this without using while loop, but how can you do that using while
> loop?
>
> Example:
>
> Enter a string: Hello world
>
> **
> *Hello world*
> **

Since others have posted so helpful answer I'm just going to rant:

1) http://docs.python.org/ <- first part (make sure you read the docs
-- and tutorial -- for the python version you installed
2) After you know how to store user input in a variable think about
what other facts you know (by examining the content of the variable)
2) Think again hard what you need to output and which parts of the
output need to match the information you already have (by doing point
2)

That shouldn't be too hard

hth
Martin

-- 
http://soup.alt.delete.co.at
http://www.xing.com/profile/Martin_Marcher
http://www.linkedin.com/in/martinmarcher

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best 3d graphics kit for CAD program???

2009-02-09 Thread TheSeeker
On Feb 9, 2:08 pm, r  wrote:
> On Feb 9, 1:33 pm, Stef Mientki  wrote:
>
> > Maya ?
> > Blender ?
> > I forgot:
> > pySoy
> > Intensity
>
> Thanks Stef,
> I actually got OpenGL to install(finally) and now i am thinking ?
> maybe? i should just go with OpenGL using the wxglcanvas. I have been
> also "messing" around with Bender but i think i want a stand alone
> application here. I don't know anything about Maya however?
>
> Thanks for the info and feel free to offer more.

Hi,

Have you considered OpenCascade:
http://www.opencascade.org/

Along with its python bindings, it might be a good alternative:
http://www.pythonocc.org/

Just a thought,
Duane
--
http://mail.python.org/mailman/listinfo/python-list


Re: Simple question - stock market simulation

2009-02-09 Thread cptn.spoon
On Feb 10, 3:29 am, Anthra Norell  wrote:
> cptn.spoon wrote:
> > I'm trying to create an incredibly simple stock market simulator to be
> > used in a childrens classroom and I'm wondering whether someone can
> > point me in the right direction.
>
> > I basically want to be able to have a stock struct as follows:
>
> > StockName = "Test"
> > StockPriceList = (12,13,12,10,10,8,10)
> > StockRisk = 0.15
> > StockQty = 2000
>
> > And then have a StockMarket struct that can contain 1 to many Stocks.
> > I then want to be able to iterate through the stocks to perform
> > operations as such:
>
> > for Stock in StockMarket:
>
> > I'm not asking for tips on the program itself, I just can't figure out
> > how to get the data structures in place. Would I use Classes or would
> > I use dictionaries? Am I completely off the mark with this?
>
> > Apologies for such a rudimentary question...I'm very new to all this.
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> If the subject is investment performance, surely your best bet is to
> hand out piggy banks.
>
> Frederic

Thank you all for your advice. It's been most helpful!

Frederic: Haha, it's more to encourage behaviour and risk management
but I agree with your sentiment!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Simple question - stock market simulation

2009-02-09 Thread cptn.spoon
On Feb 9, 6:48 pm, "Hendrik van Rooyen"  wrote:
> "cptn.spoon"  wrote:
>
> On Feb 9, 3:58 pm, Paul Rubin  wrote:
>
> >Thanks Paul! I thought this might be the case. So how would I get the
> >StockMarket class instance to contain many Stock class instances and
> >then be able to iterate through them? I'm guessing the basic structure
> >would be as follows...but I think I'm wrong:
>
> >class StockMarket:
> >  pass
>
> No.
> At this level, just use a list of instances of your Stock class.
>
> - Hendrik

How do I get a list of instances of a particular class? Is there a way
to do this dynamically?

Also, what would be the way of dynamically creating an instance of a
class based on user input (ie a user wants to create a new instance of
the Stock class via shell input)?

I'm not sure if I have the wrong mindset here.

Thanks for any help
~Phil
--
http://mail.python.org/mailman/listinfo/python-list


"Super()" confusion

2009-02-09 Thread Lionel
Hello. I've been scouring the web looking for something to clear up a
little confusion about the use of "super()" but haven't found anything
that really helps. Here's my simple example:


class Parent:
 def __init__(self, filePath):
   .
   .
   Do some processing with "filePath"
   .
   .

class Child(Parent):
 def __init__(self, filePath):
  super(Child,self).__init__(filePath)
  .
  .
  Do some additional Child-specific processing on filePath
  .
  .

As I understand it, "super()" will invoke the initializer of the base
class. There must be something wrong with the above syntax since I'm
getting:

"super(Child,self).__init__(filePath)
TypeError: super() argument 1 must be type, not classobj"

What have I done wrong? Thanks in advance for any help.

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


Re: Simple question - stock market simulation

2009-02-09 Thread Robert Kern

On 2009-02-09 17:10, cptn.spoon wrote:

On Feb 9, 6:48 pm, "Hendrik van Rooyen"  wrote:

"cptn.spoon"  wrote:

On Feb 9, 3:58 pm, Paul Rubin  wrote:


Thanks Paul! I thought this might be the case. So how would I get the
StockMarket class instance to contain many Stock class instances and
then be able to iterate through them? I'm guessing the basic structure
would be as follows...but I think I'm wrong:
class StockMarket:
  pass

No.
At this level, just use a list of instances of your Stock class.

- Hendrik


How do I get a list of instances of a particular class? Is there a way
to do this dynamically?


You *can*, but I highly recommend that you don't. Instead, just keep your own 
list of instances. When you make a new instance, just append it to the list (see 
below).


  all_stocks = []


Also, what would be the way of dynamically creating an instance of a
class based on user input (ie a user wants to create a new instance of
the Stock class via shell input)?


Define an __init__ method on your class to initialize it from given values. Use 
raw_input() to query the user for information. Convert the text input to 
whatever objects your class needs (e.g. if the user entered "10" on the prompt, 
x=raw_input() will return the string '10', so you would do int(x) to get the 
integer 10). Now, instantiate your class with the arguments:


  the_stock = Stock(name, risk, initial_price)

And append it to your list of stocks.

  all_stocks.append(the_stock)

--
Robert Kern

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

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


Re: "Super()" confusion

2009-02-09 Thread Robert Kern

On 2009-02-09 17:20, Lionel wrote:

Hello. I've been scouring the web looking for something to clear up a
little confusion about the use of "super()" but haven't found anything
that really helps. Here's my simple example:


class Parent:
  def __init__(self, filePath):
.
.
Do some processing with "filePath"
.
.

class Child(Parent):
  def __init__(self, filePath):
   super(Child,self).__init__(filePath)
   .
   .
   Do some additional Child-specific processing on filePath
   .
   .

As I understand it, "super()" will invoke the initializer of the base
class. There must be something wrong with the above syntax since I'm
getting:

"super(Child,self).__init__(filePath)
TypeError: super() argument 1 must be type, not classobj"

What have I done wrong? Thanks in advance for any help.


super() only works on the "new-style" classes introduced in Python 2.2. You need 
to make Parent subclass from object:


class Parent(object):
...

--
Robert Kern

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

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


Re: "Super()" confusion

2009-02-09 Thread Scott David Daniels

Lionel wrote:

Hello. I've been scouring the web looking for something to clear up a
little confusion about the use of "super()" but haven't found anything
that really helps. Here's my simple example:


class Parent:
 def __init__(self, filePath):...

class Child(Parent):
 def __init__(self, filePath):
  super(Child,self).__init__(filePath)
  
As I understand it, "super()" will invoke the initializer of the base
class. There must be something wrong with the above syntax since I'm
getting:
"super(Child,self).__init__(filePath)
TypeError: super() argument 1 must be type, not classobj"

What have I done wrong? Thanks in advance for any help.


To use super, you must work with descendants of "object".

So, just change your first line to:
class Parent(object):
and you should find your world back in place.

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


Re: "Super()" confusion

2009-02-09 Thread Jean-Paul Calderone

On Mon, 9 Feb 2009 15:20:05 -0800 (PST), Lionel  wrote:

Hello. I've been scouring the web looking for something to clear up a
little confusion about the use of "super()" but haven't found anything
that really helps. Here's my simple example:

[snip]

"super(Child,self).__init__(filePath)
TypeError: super() argument 1 must be type, not classobj"

What have I done wrong? Thanks in advance for any help.


Consider whether you really need to use super().

http://fuhm.net/super-harmful/

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


Re: adodb has no attribute connect

2009-02-09 Thread Diez B. Roggisch

Rahul schrieb:

Hello all,

I have to access data from database using adodb so I did

Import adodb
Conn=adodb.NewADOConnection("odbc")

Upto this it works properly but when I say


It does not. It returns None, thus the following error you see.


Conn.Connect("","","")

It gives error as

[Attributrerror]: Object Nonetype has no attribute Connect.

I have Red Hat Enterprise Linux 4
Python 2.5
Mod_python 3.3.1



According to the docs on the (very old and seemingly not actively 
developed adodb-site), "odbc" needs the Python windows extensions. As 
you are on redheat, I have difficulties believing you make these work.


Maybe mxodbc works? Or even better, ditch that ado-stuff and connect 
directly to your database. Python's DB-API is better I guess, no need 
for this attempt at mimicking windows APIs.


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


Re: wxPython vs Glade?

2009-02-09 Thread Michael Torrie
Michael Pobega wrote:
> I'm looking for opinions on the best toolkit for a beginner to use with
> wxPython. It doesn't necessarily need to be the most efficient toolkit,
> but something I can use for basic programs (a Twitter client, Wordpress
> blogging client, etc) just to learn Python.
> 
> wxWidgets seems nice because it's portable, but I'm not sure how many of
> my libraries are portable (a lot of them seem to import os), while Glade
> seems extremely simple to make a UI (but does the program end up relying
> on Glade? Or can I build it directly into GTK+?)

Glade is very nice for generating GTK guis.  If you save in the newer
format, then GTK has a built-in api called GtkBuilder for importing the
GUI, creating it, and setting up the callbacks.

To be clear, glade-generated ui files work only with GTK, not wxPython.
 If you ever find yourself coding PyQT, the QT Designer is one of the
best GUI builders on the planet.
--
http://mail.python.org/mailman/listinfo/python-list


Re: "Super()" confusion

2009-02-09 Thread Lionel
On Feb 9, 4:04 pm, Jean-Paul Calderone  wrote:
> On Mon, 9 Feb 2009 15:20:05 -0800 (PST), Lionel  
> wrote:
> >Hello. I've been scouring the web looking for something to clear up a
> >little confusion about the use of "super()" but haven't found anything
> >that really helps. Here's my simple example:
>
> > [snip]
>
> >"super(Child,self).__init__(filePath)
> >TypeError: super() argument 1 must be type, not classobj"
>
> >What have I done wrong? Thanks in advance for any help.
>
> Consider whether you really need to use super().
>
> http://fuhm.net/super-harmful/
>
> Jean-Paul

Yes, I came across that essay...and it scared me. Will my base class
initializer always get called regardless of whether or not I use super
()? If so, does this occur prior to any code in my derived class
initializer being executed (in other words, if I don't explicitly call
"super()" in my derived class, am I guaranteed that the base class
"__init__" has executed completely)? If so, then I guess I can forego
the use of "super()"
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >