Re: [Tutor] output sequentially

2011-07-27 Thread Peter Otten
lina wrote:

 I have below file,
 
 I wish the output following:
 
 The first field 169 -170 sequential, and then the filed 2 from 1-29,
 ignore the rest 4 fields,
 
   
   169CHOL   O28 1612   6.966   6.060   6.429

Read the lines from the file, sort them with a proper key function, write 
the sorted lines to a new file:

with open(source.txt) as instream:
   lines = sorted(instream, key=mykey)

with open(dest.txt, w) as outstream:
outstream.writelines(lines)

Now for the mykey() function: what should it look like?
You want to sort by the integer value of the first two columns, so you have 
to split the lines into fields and then remove the non-digits from the 
fields you are interested in. Here's an outline:

def extract_int(field):
   only_digits = ...
   return int(only_digits)

assert extract_int(169CHOL) == 169
assert extract_int(H28) == 28

def mykey(line):
fields = ...
# example: ['169CHOL', 'H29', '1611', '6.963', '6.155', '6.395']
return extract_int(fields[0]), extract_int(fields[1])

assert mykey(169CHOL   H29 1611   6.963   6.155   6.395\n) == (169, 28)

Can you fill in the blanks?


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Tkinter event activated with time

2011-07-27 Thread Emeka
Hello All,

I am putting together a small game, and I would want to enable my callback
function using time passed.

How to do something like this with Tkinter event.

from time import time

ftime  = time()
   if ftime - time()  2000:
dosomething



-- 
*Satajanus  Nig. Ltd


*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Tkinter event activated with time

2011-07-27 Thread Peter Otten
Emeka wrote:

 I am putting together a small game, and I would want to enable my callback
 function using time passed.
 
 How to do something like this with Tkinter event.
 
 from time import time
 
 ftime  = time()
if ftime - time()  2000:
 dosomething

You can schedule a function call with the after() method:

import Tkinter as tk

def scroll(s):
while True:
yield s
s = s[-1] + s[:-1]

hello = scroll(Hello world! *** )

def do_something():
label[text] = next(hello)
# play it again, after 100 msecs
label.after(100, do_something) 

root = tk.Tk()
label = tk.Label(root, font=(Times, 36))
label.pack()
do_something()
root.mainloop()


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Object Management

2011-07-27 Thread Alexander
Hello everyone. I'm having trouble wrapping my mind around a project I'm
working on. My goal is to create a program that manages (allows its users to
manipulate, search by criteria and edit) objects. There is one type of
object, for example I'll say it's a car.

There will be a central data file containing all of the cars and multiple
users will have access to it at once. I'm having trouble here, I've done
some research on MOO and twisted but I'm not sure where to turn.

Additionally I'll need a GUI! tkinter? Does anyone have any suggestions on
how to get started with tkinter? I'm overwhelmed with the amount of
documentation I've had to read and think I have to read to accomplish my
goal.

Thanks for reading, Alex.ander

-- 
Alexander
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Object Management

2011-07-27 Thread James Reynolds
On Wed, Jul 27, 2011 at 9:51 AM, Alexander rhettna...@gmail.com wrote:

 Hello everyone. I'm having trouble wrapping my mind around a project I'm
 working on. My goal is to create a program that manages (allows its users to
 manipulate, search by criteria and edit) objects. There is one type of
 object, for example I'll say it's a car.

 There will be a central data file containing all of the cars and multiple
 users will have access to it at once. I'm having trouble here, I've done
 some research on MOO and twisted but I'm not sure where to turn.

 Additionally I'll need a GUI! tkinter? Does anyone have any suggestions on
 how to get started with tkinter? I'm overwhelmed with the amount of
 documentation I've had to read and think I have to read to accomplish my
 goal.

 Thanks for reading, Alex.ander

 --
 Alexander


 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor







It sounds like your learning a lot of this as you go. Honestly, I would
scrap the GUI idea and just use Django. This will solve your mulit-user,
front end, and back end problems in one go.

Of course, that's an entire skillset onto itself and it may not be worth the
time investment. But if you already know some HTML, it would be an asset for
years to come, if you picked it up.

In which case, simply use SQlite as your backend (it comes with Python) and
then chose a GUI toolkit from there. Designing a GUI is not for the feint of
heart. Tkinter is an option, but you may want to use Wx or GTK.

A third option is to use Django to manage your backend (by creating models
and such) and then designing a gui on top of that.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Object Management

2011-07-27 Thread Knacktus

Am 27.07.2011 15:51, schrieb Alexander:

Hello everyone. I'm having trouble wrapping my mind around a project I'm
working on. My goal is to create a program that manages (allows its
users to manipulate, search by criteria and edit) objects. There is one
type of object, for example I'll say it's a car.

There will be a central data file containing all of the cars and
multiple users will have access to it at once. I'm having trouble here,
I've done some research on MOO and twisted but I'm not sure where to turn.


Sounds familiar ;-) ... on the way a lot of question are likely to 
arise. Like, OK, I've got a database. Do I load all the data at once to 
the client or only on request? What about concurrent usage by different 
clients (users)? How about authentification and authorisition? If I 
build a rich client (a python programm with GUI and network connection 
to the database), how do I manage the objects on the client?


As James already hinted, there're fantastic python web frameworks. They 
have solutions for almost all the questions that will cross your path. 
There're some relgious wars about which is the best. In my opinion 
Django is the best for starters. Do some tutorials, read the Django book 
and you'll get an idea about the overall architcture, models, views, 
templates, etc.




Additionally I'll need a GUI! tkinter? Does anyone have any suggestions
on how to get started with tkinter? I'm overwhelmed with the amount of
documentation I've had to read and think I have to read to accomplish my
goal.


I've written a rich client with PyQt which talks via web services to a 
web server. It's a lot of work! You have a lot of options, performance 
is amazing, but due to the complexity I would recommend to start with a 
web interface.


If you really need or want a rich client, you should look into Dabo:

http://dabodev.com/about

There's also another rich application framework which uses PyQt and 
looks very good, but I forgot the name. I'm not sure about wether this 
is free or commercial.





Thanks for reading, Alex.ander

--
Alexander



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] shlex parsing

2011-07-27 Thread Karim


Hello All,

I would like to parse this TCL command line with shlex:

'-option1 [get_rule A1 B2] -option2 $VAR -option3 TAG'

And I want to get the splitted list:

['-option1', '[get_rule A1 B2]', '-option2',  '$VAR', '-option3',  'TAG']

Then I will gather in tuple 2 by 2 the arguments.

I tried to the shlec properties attributes 'quotes', 'whitespace', etc...

But I make 'choux blanc'.

If somebody has complex experiences with  this module I am in.

Cheers
Karim
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] shlex parsing

2011-07-27 Thread Karim


Thank you Dan for answering.

I ended with this and gave up with shlex:

split = ['-option1', '[get_rule', 'A1', 'B2]', '-option2', '$VAR', 
'-option3', 'TAG']


procedure_found = False
result  = []

for token in split:
if not token.startswith('[') and not token.endswith(']') and not 
procedure_found:

result.append(token)
elif token.startswith('['):
procedure_found = True
_token = token
elif token.endswith(']'):
procedure_found = False
_token += ' ' + token
result.append(_token)
else:
_token += ' ' + token

print split
print result

which gives the desired values:

['-option1', '[get_rule', 'A1', 'B2]', '-option2', '$VAR', '-option3', 
'TAG']

['-option1', '[get_rule A1 B2]', '-option2', '$VAR', '-option3', 'TAG']


Sure pyParsing seems to be pretty simple but my constraint is to use
standard lib (at maximum). To bad it is not part of python standard libs.
On the other hand, I will have to regroup expression like '-option1 $VAL 
== $CONSTRAINT'

in ['-option1', '$VAL == $CONSTRAINT'].

So it seems that I have no others choicse and have to use a parser like 
pyParsing.


Regards
Karim

On 07/27/2011 10:44 PM, Dan Stromberg wrote:


I've not used the shlex module, but this feels more like an issue to 
address with a parser than for a lexical analyzer - or perhaps even 
both, since you're splitting on whitespace sometimes, and matching 
square brackets sometimes.


I've used pyparsing for stuff a bit similar to this.

Or here's a list:
http://wiki.python.org/moin/LanguageParsing

On Wed, Jul 27, 2011 at 12:30 PM, Karim karim.liat...@free.fr 
mailto:karim.liat...@free.fr wrote:



Hello All,

I would like to parse this TCL command line with shlex:

'-option1 [get_rule A1 B2] -option2 $VAR -option3 TAG'

And I want to get the splitted list:

['-option1', '[get_rule A1 B2]', '-option2',  '$VAR', '-option3',
 'TAG']

Then I will gather in tuple 2 by 2 the arguments.

I tried to the shlec properties attributes 'quotes', 'whitespace',
etc...

But I make 'choux blanc'.

If somebody has complex experiences with  this module I am in.

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





___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Getting Idle to work in Win7

2011-07-27 Thread Wayne Watson
It's been many months since I played with Python, and have forgotten how 
to bring up IDLE. If I simply click on a py file, I see what may be a 
dos window appear and quickly disappear. If I right-click on the file, 
and select IDLE, the same thing happens. If I go directly to All 
Programs, the same thing happens when I select IDLE.


--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

  The physicist uses ordinary words
  in a peculiar manner. -- Richard Feynma in
The Character of Physical Law


Web Page:www.speckledwithstars.net/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Getting Idle to work in Win7

2011-07-27 Thread Walter Prins
Hi

On 27 July 2011 22:07, Wayne Watson sierra_mtnv...@sbcglobal.net wrote:

 It's been many months since I played with Python, and have forgotten how to
 bring up IDLE. If I simply click on a py file, I see what may be a dos
 window appear and quickly disappear. If I right-click on the file, and
 select IDLE, the same thing happens. If I go directly to All Programs, the
 same thing happens when I select IDLE.


There must be something wrong with your Python installation.
Right-click-Edit with Idle and starting IDLE from All Programs works fine
for me. (Win 7 64-bit, with both Python 2.7 and 3.2 installed.)  I suggest
you reinstall Python as a start.  It might also be worthwhile to try to run
your Python script from the command line, as well as starting Idle from the
command line so you can see what error message might be printed.

Cheers

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Fall in love with bpython

2011-07-27 Thread Karim



Hello,

I use bpython interpreter. This is a very good interactive CLI.
I want to create a CLI with the same features than bpython.
But the cmd std module seems no to be used in this project...

Is there a tool where I can plug all my grammary commands line
a sort of generic box with completion, highlights, etc...

Cheers
Karim
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] shlex parsing

2011-07-27 Thread Karim

On 07/28/2011 12:11 AM, Dan Stromberg wrote:


You could probably use a recursive descent parser with the standard 
library.


But if your management is OK with pyparsing, that might be easier, and 
a bit more clear as well.


Yes, I thought to use str method partition in a recursive way but using 
pyParsing still be easer.


Thanks
Cheers



On Wed, Jul 27, 2011 at 2:08 PM, Karim karim.liat...@free.fr 
mailto:karim.liat...@free.fr wrote:



Thank you Dan for answering.

I ended with this and gave up with shlex:

split = ['-option1', '[get_rule', 'A1', 'B2]', '-option2', '$VAR',
'-option3', 'TAG']

procedure_found = False
result  = []

for token in split:
if not token.startswith('[') and not token.endswith(']') and
not procedure_found:
result.append(token)
elif token.startswith('['):
procedure_found = True
_token = token
elif token.endswith(']'):
procedure_found = False
_token += ' ' + token
result.append(_token)
else:
_token += ' ' + token

print split
print result

which gives the desired values:

['-option1', '[get_rule', 'A1', 'B2]', '-option2', '$VAR',
'-option3', 'TAG']
['-option1', '[get_rule A1 B2]', '-option2', '$VAR', '-option3',
'TAG']


Sure pyParsing seems to be pretty simple but my constraint is to use
standard lib (at maximum). To bad it is not part of python
standard libs.
On the other hand, I will have to regroup expression like
'-option1 $VAL == $CONSTRAINT'
in ['-option1', '$VAL == $CONSTRAINT'].

So it seems that I have no others choicse and have to use a parser
like pyParsing.

Regards
Karim


On 07/27/2011 10:44 PM, Dan Stromberg wrote:


I've not used the shlex module, but this feels more like an issue
to address with a parser than for a lexical analyzer - or perhaps
even both, since you're splitting on whitespace sometimes, and
matching square brackets sometimes.

I've used pyparsing for stuff a bit similar to this.

Or here's a list:
http://wiki.python.org/moin/LanguageParsing

On Wed, Jul 27, 2011 at 12:30 PM, Karim karim.liat...@free.fr
mailto:karim.liat...@free.fr wrote:


Hello All,

I would like to parse this TCL command line with shlex:

'-option1 [get_rule A1 B2] -option2 $VAR -option3 TAG'

And I want to get the splitted list:

['-option1', '[get_rule A1 B2]', '-option2',  '$VAR',
'-option3',  'TAG']

Then I will gather in tuple 2 by 2 the arguments.

I tried to the shlec properties attributes 'quotes',
'whitespace', etc...

But I make 'choux blanc'.

If somebody has complex experiences with  this module I am in.

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








___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Object Management

2011-07-27 Thread Alan Gauld

Alexander wrote:

Hello everyone. I'm having trouble wrapping my mind around a project I'm
working on. My goal is to create a program that manages (allows its users to
manipulate, search by criteria and edit) objects. There is one type of
object, for example I'll say it's a car.

There will be a central data file containing all of the cars and multiple
users will have access to it at once. I'm having trouble here, I've done
some research on MOO and twisted but I'm not sure where to turn.


I'd forget twisted etc for this, it sounds more like a traditional 
database is whats needed.




Additionally I'll need a GUI! tkinter? Does anyone have any suggestions on
how to get started with tkinter? I'm overwhelmed with the amount of
documentation I've had to read and think I have to read to accomplish my
goal.


Learning any GUI is a painful leaning curve. If you really need a 
desktop client rather than a web based solution I'd look at Dabo.
It has a GUI builder (based on wxPython rather than Tkinter) and is 
focused on data oriented applications.


But if you can go down the web root then most python web frameworks will 
provide both the UI and database elements for you and you get a lot of 
standard functionality (login etc) for free...



HTH,

Alan G.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fall in love with bpython

2011-07-27 Thread Alan Gauld

Karim wrote:


I use bpython interpreter. This is a very good interactive CLI.


I had never heard of it and had to google for it.
It appears to be a curses based CLI for *nix and MacOS



I want to create a CLI with the same features than bpython.
But the cmd std module seems no to be used in this project...


Why not read the bpython source to see what they used?
Thats the big advantage of open source - its open!
(Although they don't make the source explicitly available,
I'm assuming the tar file contains the source- it might
even be in Python!)

They use pygments to parse the source as you type.
That would be worth investigating too...


HTH,

Alan G.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Object Management

2011-07-27 Thread Alexander
On Tue, Jul 26, 2011 at 6:25 PM, Alan Gauld alan.ga...@btinternet.comwrote:

 Alexander wrote:

 Hello everyone. I'm having trouble wrapping my mind around a project I'm
 working on. My goal is to create a program that manages (allows its users
 to
 manipulate, search by criteria and edit) objects. There is one type of
 object, for example I'll say it's a car.

 There will be a central data file containing all of the cars and multiple
 users will have access to it at once. I'm having trouble here, I've done
 some research on MOO and twisted but I'm not sure where to turn.


 I'd forget twisted etc for this, it sounds more like a traditional database
 is whats needed.



  Additionally I'll need a GUI! tkinter? Does anyone have any suggestions on
 how to get started with tkinter? I'm overwhelmed with the amount of
 documentation I've had to read and think I have to read to accomplish my
 goal.


 Learning any GUI is a painful leaning curve. If you really need a desktop
 client rather than a web based solution I'd look at Dabo.
 It has a GUI builder (based on wxPython rather than Tkinter) and is focused
 on data oriented applications.

 But if you can go down the web root then most python web frameworks will
 provide both the UI and database elements for you and you get a lot of
 standard functionality (login etc) for free...


 HTH,

 Alan G.





-- 
Thanks for the replies Alan, James, and Knacktus. I'll research Django. I've
been trying to work on this project for a few months and just came across
the mailing list today. I appreciate your help, thanks!
Alexander
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Getting Idle to work in Win7

2011-07-27 Thread Prasad, Ramit
From: tutor-bounces+ramit.prasad=jpmchase@python.org 
[mailto:tutor-bounces+ramit.prasad=jpmchase@python.org] On Behalf Of Walter 
Prins
Sent: Wednesday, July 27, 2011 4:39 PM
To: tutor@python.org
Subject: Re: [Tutor] Getting Idle to work in Win7

Hi
On 27 July 2011 22:07, Wayne Watson 
sierra_mtnv...@sbcglobal.netmailto:sierra_mtnv...@sbcglobal.net wrote:
It's been many months since I played with Python, and have forgotten how to 
bring up IDLE. If I simply click on a py file, I see what may be a dos window 
appear and quickly disappear. If I right-click on the file, and select IDLE, 
the same thing happens. If I go directly to All Programs, the same thing 
happens when I select IDLE.

There must be something wrong with your Python installation.  
Right-click-Edit with Idle and starting IDLE from All Programs works fine 
for me. (Win 7 64-bit, with both Python 2.7 and 3.2 installed.)  I suggest you 
reinstall Python as a start.  It might also be worthwhile to try to run your 
Python script from the command line, as well as starting Idle from the command 
line so you can see what error message might be printed.

Cheers

Walter

Open cmd.exe and then navigate to the directory where Python is installed 
(C:\Python27) for me and then cd into the Lib\idlelib directory and run 
idle.bat. Hopefully there should be some errors that show in the window. If not 
you can try running it ..\..\pythonw.exe idle.pyw and hopefully that will 
show the problem.


Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423







This communication is for informational purposes only. It is not
intended as an offer or solicitation for the purchase or sale of
any financial instrument or as an official confirmation of any
transaction. All market prices, data and other information are not
warranted as to completeness or accuracy and are subject to change
without notice. Any comments or statements made herein do not
necessarily reflect those of JPMorgan Chase  Co., its subsidiaries
and affiliates.

This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law. If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED. Although this transmission and any
attachments are believed to be free of any virus or other defect
that might affect any computer system into which it is received and
opened, it is the responsibility of the recipient to ensure that it
is virus free and no responsibility is accepted by JPMorgan Chase 
Co., its subsidiaries and affiliates, as applicable, for any loss
or damage arising in any way from its use. If you received this
transmission in error, please immediately contact the sender and
destroy the material in its entirety, whether in electronic or hard
copy format. Thank you.

Please refer to http://www.jpmorgan.com/pages/disclosures for
disclosures relating to European legal entities.___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fall in love with bpython

2011-07-27 Thread Karim

On 07/27/2011 12:34 AM, Alan Gauld wrote:

Karim wrote:


I use bpython interpreter. This is a very good interactive CLI.


I had never heard of it and had to google for it.
It appears to be a curses based CLI for *nix and MacOS


Ah Windows user.




I want to create a CLI with the same features than bpython.
But the cmd std module seems no to be used in this project...


Why not read the bpython source to see what they used?
Thats the big advantage of open source - its open!
(Although they don't make the source explicitly available,
I'm assuming the tar file contains the source- it might
even be in Python!)

They use pygments to parse the source as you type.
That would be worth investigating too...



Yes I saw mainly pygments which is an OpenSource project...
But, I must admit. I will spend 6 months before understanding this.
Rhahaaa... This level is high! I saw too cmd2 which is fully compatible 
and inherit from cmd.

But not quite as fun!

The main module cli.py is 1700 lignes and the architecture is not very 
well documented.

We will see If I can make any progress during the next month.

Thanks Alan

PS: Are you still making some hiking in the higlands. Beautiful photos I 
have seen on your web site!


Cheers
Alan



HTH,

Alan G.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fall in love with bpython

2011-07-27 Thread Karim

On 07/28/2011 12:31 AM, Michael Poeltl wrote:

hi,

have you heard abut ipython? maybe that's helpful for you?
http://ipython.scipy.org/moin/python


Hello Michael,

Yes I saw some article where Ipython and Bpython CLI integrations was 
made in Django.


Thanks for the link I will evaluate it as well.

Cheers
Karim


Michael
* Karimkarim.liat...@free.fr  [2011-07-27 23:46]:


Hello,

I use bpython interpreter. This is a very good interactive CLI.
I want to create a CLI with the same features than bpython.
But the cmd std module seems no to be used in this project...

Is there a tool where I can plug all my grammary commands line
a sort of generic box with completion, highlights, etc...

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



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fall in love with bpython

2011-07-27 Thread Walter Prins
Hi Karim

On 28 July 2011 00:04, Karim karim.liat...@free.fr wrote:

 On 07/27/2011 12:34 AM, Alan Gauld wrote:

 Karim wrote:

  I use bpython interpreter. This is a very good interactive CLI.


 I had never heard of it and had to google for it.
 It appears to be a curses based CLI for *nix and MacOS


 Ah Windows user.


Thanks for mentioning bpython -- I had also not heard of it but it duly
installed on my ubuntu box from the repositories!  I've browsed the code --
it uses ncurses to do the screen IO.  You can always read the code, but, as
you intimated, unless you're pretty familiar with somewhat large codebases
and ncurses it might not be that much use to you just yet. ... Still, it
might be worth having a look at the source... :)

http://hg.bpython-interpreter.org/bpython/src/bcd836c859aa/bpython/

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fall in love with bpython

2011-07-27 Thread Karim

On 07/28/2011 01:32 AM, Walter Prins wrote:

Hi Karim

On 28 July 2011 00:04, Karim karim.liat...@free.fr 
mailto:karim.liat...@free.fr wrote:


On 07/27/2011 12:34 AM, Alan Gauld wrote:

Karim wrote:

I use bpython interpreter. This is a very good interactive
CLI.


I had never heard of it and had to google for it.
It appears to be a curses based CLI for *nix and MacOS


Ah Windows user.


Thanks for mentioning bpython -- I had also not heard of it but it 
duly installed on my ubuntu box from the repositories!  I've browsed 
the code -- it uses ncurses to do the screen IO.  You can always read 
the code, but, as you intimated, unless you're pretty familiar with 
somewhat large codebases and ncurses it might not be that much use to 
you just yet. ... Still, it might be worth having a look at the 
source... :)


http://hg.bpython-interpreter.org/bpython/src/bcd836c859aa/bpython/

Walter


Hi,

I am using ubuntu too.
I used to write large API but in fact I did not know curses and I wanted 
to see in the code
where the keywords are 'injected' to try with my own grammar. I still 
have to study the details.
But it seems that the keywords are imported dynamically from 
__builtins__ module. Don't know yet

how to configure or modify it.

Thanks for your advice
Regards
Karim



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Object Management

2011-07-27 Thread Steven D'Aprano

Alexander wrote:

Hello everyone. I'm having trouble wrapping my mind around a project I'm
working on. My goal is to create a program that manages (allows its users to
manipulate, search by criteria and edit) objects. There is one type of
object, for example I'll say it's a car.



This is called a database. Implementing databases correctly is a HUGE 
job: more work than writing an operating system.


Take my advice and choose an existing database. If your needs are light, 
use SQLite. If your needs are heavy, MySQL or Postgres. If you need to 
impress corporate buyers with more money than sense, and you have a 
large budget, Oracle. Then concentrate on building the user-friendly 
front-end to the database. That alone will be a big job.



If you are happy with a web-interface, rather than a desktop GUI, I 
recommend you look at CherryPy. It's a nice, lightweight web framework 
without the learning curve of Django and similar.



--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Assigning range

2011-07-27 Thread Alexander Quest
Does anyone know how to assign a certain numerical range to a variable, and
then choose the number that is the middle of that range? For example, I want
to assign the variable X a range between 1 and 50, and then I want to have
the middle of that range (25) return with some command when I call it
(perhaps rangemid or something like that?). In pseudocode, I am trying to
say X = range [1,50], return middle of range (which should return 25) but I
don't know how to code it. This is for a basic program I'm trying to write
where the player thinks of a number and the computer tries to guess the
number in as few tries as possible. Thanks for any help!

-Alex
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] shlex parsing

2011-07-27 Thread Steven D'Aprano

Karim wrote:


Hello All,

I would like to parse this TCL command line with shlex:

'-option1 [get_rule A1 B2] -option2 $VAR -option3 TAG'

And I want to get the splitted list:

['-option1', '[get_rule A1 B2]', '-option2',  '$VAR', '-option3',  'TAG']

Then I will gather in tuple 2 by 2 the arguments.

I tried to the shlec properties attributes 'quotes', 'whitespace', etc...


I don't understand what you are doing here. Please show the code you use.

The shlex module doesn't support bracketed expressions. I recommend you 
write a post-processor. Start with doing this:


 import shlex
 text = '-option1 [get_rule A1 B2] -option2 $VAR -option3 TAG'
 shlex.split(text)
['-option1', '[get_rule', 'A1', 'B2]', '-option2', '$VAR', '-option3', 
'TAG']


then take that list and reassemble the pieces starting with '[' until 
']' Something like this, untested:



def reassemble(items):
result = []
bracketed = False
current = ''
for item in items:
if item.startswith('['):
bracketed = True
if bracketed:
current += item
if item.endswith(']'):
bracketed = False
result.append(current)
current = ''
else:
 result.append(item)
return result




But I make 'choux blanc'.


I don't know what that means.




--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Assigning range

2011-07-27 Thread Steven D'Aprano

Alexander Quest wrote:

Does anyone know how to assign a certain numerical range to a variable, and
then choose the number that is the middle of that range? For example, I want
to assign the variable X a range between 1 and 50, and then I want to have
the middle of that range (25) return with some command when I call it
(perhaps rangemid or something like that?). In pseudocode, I am trying to
say X = range [1,50], return middle of range (which should return 25) but I
don't know how to code it. This is for a basic program I'm trying to write
where the player thinks of a number and the computer tries to guess the
number in as few tries as possible. Thanks for any help!



Forget about using range, that just adds meaningless complexity.

What is important is that you have a lower bound, and a higher bound: 
two numbers, instead of how ever many (possible thousands, or millions!) 
in range(low, high).


middle = (low+high)//2



--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] shlex parsing

2011-07-27 Thread Karim

On 07/28/2011 02:27 AM, Steven D'Aprano wrote:

Karim wrote:


Hello All,

I would like to parse this TCL command line with shlex:

'-option1 [get_rule A1 B2] -option2 $VAR -option3 TAG'

And I want to get the splitted list:

['-option1', '[get_rule A1 B2]', '-option2',  '$VAR', '-option3',  
'TAG']


Then I will gather in tuple 2 by 2 the arguments.

I tried to the shlec properties attributes 'quotes', 'whitespace', 
etc...


I don't understand what you are doing here. Please show the code you use.

The shlex module doesn't support bracketed expressions. I recommend 
you write a post-processor. Start with doing this:


 import shlex
 text = '-option1 [get_rule A1 B2] -option2 $VAR -option3 TAG'
 shlex.split(text)
['-option1', '[get_rule', 'A1', 'B2]', '-option2', '$VAR', '-option3', 
'TAG']


then take that list and reassemble the pieces starting with '[' until 
']' Something like this, untested:



def reassemble(items):
result = []
bracketed = False
current = ''
for item in items:
if item.startswith('['):
bracketed = True
if bracketed:
current += item
if item.endswith(']'):
bracketed = False
result.append(current)
current = ''
else:
 result.append(item)
return result





Yes Steven this is the kind of code I wrote in a post earlier, but I 
forget to reinit as you did current equal to _token in my code, thanks 
for that for showing me to simply if/elif/elif/else levels:


Previous code was:

I ended up with this and gave up with shlex:

split = ['-option1', '[get_rule', 'A1', 'B2]', '-option2', '$VAR', 
'-option3', 'TAG']


procedure_found = False
result  = []

for token in split:
if not token.startswith('[') and not token.endswith(']') and not 
procedure_found:

result.append(token)
elif token.startswith('['):
procedure_found = True
_token = token
elif token.endswith(']'):
procedure_found = False
_token += ' ' + token
result.append(_token)
else:
_token += ' ' + token

print split
print result


But I make 'choux blanc'.


I don't know what that means.

This means 'white cabbage' in french = 'unsuccessful try'

Cheers
Karim
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Assigning range

2011-07-27 Thread Alexander Quest
Thanks Steven- I'll try that out.

-Alex

On Wed, Jul 27, 2011 at 5:40 PM, Steven D'Aprano st...@pearwood.infowrote:

 Alexander Quest wrote:

 Does anyone know how to assign a certain numerical range to a variable,
 and
 then choose the number that is the middle of that range? For example, I
 want
 to assign the variable X a range between 1 and 50, and then I want to
 have
 the middle of that range (25) return with some command when I call it
 (perhaps rangemid or something like that?). In pseudocode, I am trying to
 say X = range [1,50], return middle of range (which should return 25) but
 I
 don't know how to code it. This is for a basic program I'm trying to write
 where the player thinks of a number and the computer tries to guess the
 number in as few tries as possible. Thanks for any help!



 Forget about using range, that just adds meaningless complexity.

 What is important is that you have a lower bound, and a higher bound: two
 numbers, instead of how ever many (possible thousands, or millions!) in
 range(low, high).

 middle = (low+high)//2



 --
 Steven

 __**_
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/**mailman/listinfo/tutorhttp://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Assigning range :p:

2011-07-27 Thread Thomas C. Hicks
On Wed, 27 Jul 2011 20:16:31 -0400
Alexander Quest alexxqu...@gmail.com wrote:

 Does anyone know how to assign a certain numerical range to a
 variable, and then choose the number that is the middle of that
 range? For example, I want to assign the variable X a range between
 1 and 50, and then I want to have the middle of that range (25)
 return with some command when I call it (perhaps rangemid or
 something like that?). In pseudocode, I am trying to say X = range
 [1,50], return middle of range (which should return 25) but I don't
 know how to code it. This is for a basic program I'm trying to write
 where the player thinks of a number and the computer tries to guess
 the number in as few tries as possible. Thanks for any help!
 
 -Alex

There are probably better ways but this worked for me:

x=range(1,50)
mid=x[len(x)/2]

You do have to keep in mind the way python counts list indices for a
range call - i.e. x=range(1,50) will give you a list with all numbers 1
to 49 in it.

Hope that helps!

tom
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how to temporarily disable a function

2011-07-27 Thread Pete O'Connell
Hi I was wondering if there is a way to disable a function.
Hi have a GUI grid snapping function that I use in a program called Nuke
(the film compositing software)

Here is the function (which loads when Nuke loads):
###
def theAutoplaceSnap():
try:
nuke.thisNode().autoplace()
n = nuke.allNodes();
for i in n:
  nuke.autoplaceSnap(i)
except:
pass

nuke.addOnUserCreate(theAutoplaceSnap)
###

I have many functions which get loaded, but this particular one needs to be
disabled when I am viewing another compositors script in the gui.

I have a python script editor in Nuke in which I can run code if need be to
run code on the fly.

Help
-- 
Pete
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Assigning range

2011-07-27 Thread Donald Wilson
You could start with an anonymous function using the lambda operator, such as:



mid_range = lambda x: x[len(x) // 2]

Note: If you use len(x) / 2 in python 3.x you will get a TypeError because the 
division operator / returns a float. Floor // returns an int in 2.x and 3.x.

Then use either:

x = range(1000, 4001)
mid_x = mid_range(x) # mid_x == 2500

or…

mid_x = mid_range(range(500, 751)) # mid_x == 625

etc. to retrieve the middle element.

You can extract the mid point of any sequence type, such as a string, using 
this function.

mid_x = mid_range(‘12345678987654321’) # mid_x == ‘9’



middle_number = lambda lo, hi: abs(lo - hi) // 2

will work if you just need the mid point of two numbers; either ints or floats.

mid_x = middle_number(0, 1000) # mid_x = 500

DW

On Jul 27, 2011, at 8:16 PM, Alexander Quest wrote:

 Does anyone know how to assign a certain numerical range to a variable, and 
 then choose the number that is the middle of that range? For example, I want 
 to assign the variable X a range between 1 and 50, and then I want to have 
 the middle of that range (25) return with some command when I call it 
 (perhaps rangemid or something like that?). In pseudocode, I am trying to say 
 X = range [1,50], return middle of range (which should return 25) but I don't 
 know how to code it. This is for a basic program I'm trying to write where 
 the player thinks of a number and the computer tries to guess the number in 
 as few tries as possible. Thanks for any help!
 
 -Alex
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Assigning range

2011-07-27 Thread Alexander Quest
Thanks for that Donald!

-Alex

On Wed, Jul 27, 2011 at 8:16 PM, Donald Wilson donald...@me.com wrote:

 You could start with an anonymous function using the lambda operator, such
 as:

 

 mid_range = lambda x: x[len(x) // 2]

 Note: If you use len(x) / 2 in python 3.x you will get a TypeError because
 the division operator / returns a float. Floor // returns an int in 2.x and
 3.x.

 Then use either:

 x = range(1000, 4001)
 mid_x = mid_range(x) # mid_x == 2500

 or…

 mid_x = mid_range(range(500, 751)) # mid_x == 625

 etc. to retrieve the middle element.

 You can extract the mid point of any sequence type, such as a string, using
 this function.

 mid_x = mid_range(‘12345678987654321’) # mid_x == ‘9’

 

 middle_number = lambda lo, hi: abs(lo - hi) // 2

 will work if you just need the mid point of two numbers; either ints or
 floats.

 mid_x = middle_number(0, 1000) # mid_x = 500

 DW

 On Jul 27, 2011, at 8:16 PM, Alexander Quest wrote:

  Does anyone know how to assign a certain numerical range to a variable,
 and then choose the number that is the middle of that range? For example, I
 want to assign the variable X a range between 1 and 50, and then I want to
 have the middle of that range (25) return with some command when I call it
 (perhaps rangemid or something like that?). In pseudocode, I am trying to
 say X = range [1,50], return middle of range (which should return 25) but I
 don't know how to code it. This is for a basic program I'm trying to write
 where the player thinks of a number and the computer tries to guess the
 number in as few tries as possible. Thanks for any help!
 
  -Alex
  ___
  Tutor maillist  -  Tutor@python.org
  To unsubscribe or change subscription options:
  http://mail.python.org/mailman/listinfo/tutor

 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor