Re: [Tutor] re-initialising shells

2007-12-21 Thread Alan Gauld

Jim Morcombe [EMAIL PROTECTED] wrote

 I have changed qwerty and saved it away.
 I have then run my program (F5) and the program acts as
 if it is using an old version of qwerty.

You need to reload the module to pick up the changes.

 help(reload)
Help on built-in function reload in module __builtin__:

reload(...)
reload(module) - module

Reload the module.  The module must have been successfully 
imported before.


In addition there is a Restart menu option in IDLE that will 
effectively
give you a new empty shell environment if you have lots of imported 
modules.

However I'm not sure if reload will work if you use the from X import 
*
approach since that imports all of the names rather than the module 
itself.
In that case restart is probably the best bet - or switch to the safer 
import X
style.

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Using 'join ' function to create a string

2007-12-21 Thread lechtlr
Hi there,

I would like to know what is the best way to create a string object from two 
different lists using 'join' function. For example, I have X = ['a', 'b', 'c', 
'd', 'e'] and Y = [1, 2, 3, 4, 5]. From X and Y, I want to create a string Z = 
'a:1, b:2, c:3, d:4, e:5'.

Any help would greatly be appreciated.
-Lex 

  
   
-
Looking for last minute shopping deals?  Find them fast with Yahoo! Search.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using 'join ' function to create a string

2007-12-21 Thread Dave Kuhlman
On Fri, Dec 21, 2007 at 09:33:31AM -0700, Eric Brunson wrote:
 lechtlr wrote:
  Hi there,
 
  I would like to know what is the best way to create a string object 
  from two different lists using 'join' function. For example, I have X 
  = ['a', 'b', 'c', 'd', 'e'] and Y = [1, 2, 3, 4, 5]. From X and Y, I 
  want to create a string Z = 'a:1, b:2, c:3, d:4, e:5'.
 
 How about something like this:
 
 , .join( '%s:%s' % ( x, y ) for x, y in zip( X, Y ) )

Slick.  I believe that the argument you are passing to join() is
the result of a generator expression.  Am I right?

And, I did not know that str.join(seq) could take an iterator as
opposed to a plain sequence.  Thanks for showing us that.

Back to the original poster's problem, you could also try map() and
a lambda:

', '.join(map(lambda x,y: '%s:%s' % (x, y, ), X, Y))

Or, maybe unrolling it makes it more readable:

In [31]: fn = lambda x,y: '%s:%s' % (x, y, )
In [32]: ', '.join(map(fn, a, b))
Out[32]: 'aa:11, bb:22, cc:33'

- Dave

-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using 'join ' function to create a string

2007-12-21 Thread Eric Brunson
lechtlr wrote:
 Hi there,

 I would like to know what is the best way to create a string object 
 from two different lists using 'join' function. For example, I have X 
 = ['a', 'b', 'c', 'd', 'e'] and Y = [1, 2, 3, 4, 5]. From X and Y, I 
 want to create a string Z = 'a:1, b:2, c:3, d:4, e:5'.

How about something like this:

, .join( '%s:%s' % ( x, y ) for x, y in zip( X, Y ) )

Yields:  'a:1, b:2, c:3, d:4, e:5'


 Any help would greatly be appreciated.
 -Lex

 
 Looking for last minute shopping deals? Find them fast with Yahoo! 
 Search. 
 http://us.rd.yahoo.com/evt=51734/*http://tools.search.yahoo.com/newsearch/category.php?category=shopping
  

 

 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor
   

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using 'join ' function to create a string

2007-12-21 Thread bob gailer
lechtlr wrote:
 Hi there,

 I would like to know what is the best way to create a string object 
 from two different lists using 'join' function. For example, I have X 
 = ['a', 'b', 'c', 'd', 'e'] and Y = [1, 2, 3, 4, 5]. From X and Y, I 
 want to create a string Z = 'a:1, b:2, c:3, d:4, e:5'.

Best way? Depends on what you mean by best.

My solution:

Z = ', '.join(i+':'+str(j) for i, j in zip(X,Y))

It's interesting to note how close your output is to a dictionary display:

dict(zip(X,Y)) - {'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4}

BTW is is customary in Python to start variable names with lower case 
letters (x,y,z) in this case.
Title case  is then used for Classes
CAPS is used for CONSTANTS
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Cant write new line at end of file append

2007-12-21 Thread dave selby
Hi all,

I need to write a newline at the end of a string I am appending to a
file. I tried ...

journal.write('%s#%s\n' % (jpeg[:-4], self.snap_init[feed]))

The text is all there but no new line at the end  any idea what I
am doing wrong ? ... thought \n would do it.

Cheers

Dave


-- 

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


Re: [Tutor] Using 'join ' function to create a string

2007-12-21 Thread christopher . henk
this works for me.

Z=, .join([%s:%s %(a,Y[b]) for b,a in enumerate(X)])






lechtlr [EMAIL PROTECTED] 
Sent by: [EMAIL PROTECTED]
12/21/2007 11:00 AM

To
tutor@python.org
cc

Subject
[Tutor] Using 'join ' function to create a string






Hi there,

I would like to know what is the best way to create a string object from 
two different lists using 'join' function. For example, I have X = ['a', 
'b', 'c', 'd', 'e'] and Y = [1, 2, 3, 4, 5]. From X and Y, I want to 
create a string Z = 'a:1, b:2, c:3, d:4, e:5'.
Any help would greatly be appreciated.
-Lex 
 Looking for last minute shopping deals? Find them fast with Yahoo! 
Search.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Challenge 2

2007-12-21 Thread David Holland
I did this and got this string :-

i hope you didnt translate it by hand. thats what computers are for. doing it 
in by hand is inefficient and that's why this text is so long. using 
string.maketrans() is recommended. now apply on the url
Is that the answer because it does not solve the problem when I apply it to the 
url.



 First they came for the Danes, but I did not speak out because I am not a Dane.

   
-
 Support the World Aids Awareness campaign this month with Yahoo! for Good___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python CLI parser

2007-12-21 Thread Martin Marcher
Hello,

could you have a short review of my CLI package.

What it provides is a simple interface to create a shell. I'll be
using it inside a bot I'm writing to manage it.

Features:
 * pluggable commands
 * works over streams instead of stdin/stdout/stderr so it should be
network aware (right?)

Unfeatures:
 * not documented at all, right now

Todos (for me of course, not for you, but open to suggestions):
 * import readline
 * provide TAB completion
 * make CTRL+d also a quitcommand
 * remove hardcoded quitCommands only provide defaults

Necessary interface for a command:
function(*args) returning a string (No smart output of dicts, list or suche yet)

Builtin commands are noop and and echo.

To run it do python main.py
To leave it use quit or exit

any comments are welcome, especially how I could make CTRL+d leave my shell

and I'm not looking at something that provides, I'm pretty sure
someone did a similiar thing already :)

thanks
martin

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours


cli.tar.bz2
Description: BZip2 compressed data
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Design Outline question for personal project

2007-12-21 Thread jupiejupe

(please forgive the unclear thought process i am still trying to figure out
what i need done and the order there of)
i am going to set up a network of zigbee nodes.
when a event such as: motion movement or touch awakens node 
i want it's alert to the network to trigger a programmed response.

what i have to figure out is 
using a database maybe mysql or (cherrypy seems interesting as a http frame
(can it send pop3 or imap? do i need a database if it does?).
to store the node id's numbers and the email address i want sent.
i need that node number to send it's associated email message to me at my
account.

so i believe that the zigbee node's have id already pre-programmed
so that should not be an issuse.

once the event (i'll need to have a program to take that report? or does the
database do that already?) has been reported to the database, 
the node id should trigger an email? (do i need an email client to send that
or does sockets have some thing to do with that?) that's really all that i
can think i need which most likey means i am missing the boat.


so i figure that i need to study as well as python.
cherrypy:
  has a mini sever and database so i can use that instead of mysql?
Twisted mail?
  do i have to use all of twisted or can i just use to mail part?
socket?
  okay i will google it for some gen. info but pointers of focus can
really help
am i missing anything? 


thanks any bits of info helps just an non-cpu kinda guy with a plan.
-- 
View this message in context: 
http://www.nabble.com/Design-Outline-question-for-personal-project-tp14460833p14460833.html
Sent from the Python - tutor mailing list archive at Nabble.com.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Public Python Library Code

2007-12-21 Thread jupiejupe

hello everyone i have just started to learn python, i know a little html, so
this is my real first language. i am finding so much wondering advice
sharing and tips, (a special nod to alan g.  kent j.) :clap:

i am wondering if there is a place a code library. i have spent way to much
time window shopping all of the message, some give me ideas (yes i am going
to be writing a program, if i get enough of a grasp). although i do count it
as study time, it's a messing place to find code, (alan, i have checked out
your site. you know your stuff but it's a full meal=)). i enjoy looking at
the different ways ya'll write the different code for the same task. i would
not mind starting a new child forum and start collecting code to jump start
a code library.
question::confused:
is that out of line? copyrights and what not, or is that okay, being this is
a public forum and those are like opinions?%-|

if anyone has any suggests i am all ears.

also if you one would like to point me in the right direct as to what i
should be focusing on in regard to my personaly project.
  
-- 
View this message in context: 
http://www.nabble.com/Public-Python-Library-Code-tp14460465p14460465.html
Sent from the Python - tutor mailing list archive at Nabble.com.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Design Outline question for personal project

2007-12-21 Thread jupiejupe



jupiejupe wrote:
 
 so i figure that i need to study as well as python.
 
 thanks any bits of info helps just an non-cpu kinda guy with a plan.
 

redefining list:
cherrypy:
  has a mini sever and database so i can use that instead of mysql?
Twisted mail? 
  do i have to use all of twisted or can i just use to mail part? 
socket?
  okay i will google it
am i missing anything?
 
-- 
View this message in context: 
http://www.nabble.com/Design-Outline-question-for-personal-project-tp14460833p14461182.html
Sent from the Python - tutor mailing list archive at Nabble.com.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Challenge 2

2007-12-21 Thread Alan Gauld
David Holland [EMAIL PROTECTED] wrote


 i hope you didnt translate it by hand. thats what computers are 
 for.
 doing it in by hand is inefficient and that's why this text is so 
 long.
 using string.maketrans() is recommended. now apply on the url

 Is that the answer because it does not solve the problem when I 
 apply it to the url.

I believe (its a while since I did the challenge) that you have solved 
it and
got to that page. However you could have solved it the hard way so the 
note
is telling you the esy way. Now apply that easy way to the url to get 
the url
of the next challenge.

At least thats how I remember it, but it is an adventure game after 
all...

Alan G. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Design Outline question for personal project

2007-12-21 Thread Alan Gauld

jupiejupe [EMAIL PROTECTED] wrote

 i am going to set up a network of zigbee nodes.
 when a event such as: motion movement or touch awakens node
 i want it's alert to the network to trigger a programmed response.

 what i have to figure out is using a database maybe mysql or

Yes, and you might find it useful to define a Node as a class.

 (cherrypy seems interesting as a http frame (can it send pop3
 or imap? do i need a database if it does?).

Yes it can do pop and imap vuia standard python pop and imap email
modules and no it doesn't need a database for email. Databases just
store data and allow you to retrieve it. (OK some have fancy 
trigger/event
mechanisms too)

 so i believe that the zigbee node's have id already pre-programmed
 so that should not be an issuse.

Sounds like it.

 once the event (i'll need to have a program to take that report? or 
 does the
 database do that already?) has been reported to the database,

You probably want a node object to retrieve the data from the database
and use that to send the email usong the standard python email 
modules.

 the node id should trigger an email? (do i need an email client to 
 send that
 or does sockets have some thing to do with that?) that's really all 
 that i
 can think i need which most likey means i am missing the boat.

Sockets are involved bt the email modules should shield you from all 
of that.

 so i figure that i need to study as well as python.
 cherrypy:
  has a mini sever and database so i can use that instead of 
 mysql?

You could use standard CGI for this but CherryPy might make it easier.

 Twisted mail?
  do i have to use all of twisted or can i just use to mail 
 part?
 socket?

You definitely don't need Twisted at this stage.
Standard Python email modules should do all you need.

You might want some classes and hence some OOP

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Public Python Library Code

2007-12-21 Thread Alan Gauld

jupiejupe [EMAIL PROTECTED] wrote

 i am wondering if there is a place a code library.

There are several.
For production code look in the standard library and
the Python Cheeseshop - a place fort contributed modules.
And don't forget to read the sample scripts that come with
the Python download

For sample programs and simpler projects try the Useless
Python web site. The old site (linked from the page) had a
lot of contributed short code samples. I'm not sure about the
latest incarnation.

Finally try the ActiveState site which has a Recipes section
(or Cookbook) for solving common problems (there is a paper
book containing the most common).

There are plebnty other sites too but that should be enough
to start!

i have spent way to much
 time window shopping all of the message, some give me ideas (yes i 
 am going
 to be writing a program, if i get enough of a grasp). although i do 
 count it
 as study time, it's a messing place to find code, (alan, i have 
 checked out
 your site. you know your stuff but it's a full meal=)). i enjoy 
 looking at
 the different ways ya'll write the different code for the same task. 
 i would
 not mind starting a new child forum and start collecting code to 
 jump start
 a code library.
 question::confused:
 is that out of line? copyrights and what not, or is that okay, being 
 this is
 a public forum and those are like opinions?%-|

 if anyone has any suggests i am all ears.

 also if you one would like to point me in the right direct as to 
 what i
 should be focusing on in regard to my personaly project.

 -- 
 View this message in context: 
 http://www.nabble.com/Public-Python-Library-Code-tp14460465p14460465.html
 Sent from the Python - tutor mailing list archive at Nabble.com.

 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor
 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Cant write new line at end of file append

2007-12-21 Thread Tiger12506

- Original Message - 
From: dave selby [EMAIL PROTECTED]
To: Python Tutor tutor@python.org
Sent: Friday, December 21, 2007 12:03 PM
Subject: [Tutor] Cant write new line at end of file append


 Hi all,

 I need to write a newline at the end of a string I am appending to a
 file. I tried ...

 journal.write('%s#%s\n' % (jpeg[:-4], self.snap_init[feed]))

 The text is all there but no new line at the end  any idea what I
 am doing wrong ? ... thought \n would do it.

 Cheers

 Dave

Different operating systems deal with newline differently, and sometimes 
libraries are built upon the assumption that a particular operating system 
uses a particular style of newline. Have you tried \r\n? 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Challenge 2

2007-12-21 Thread Tiger12506
I did this and got this string :-

 i hope you didnt translate it by hand. thats what computers are for. 
 doing it in by hand is inefficient and that's why this text is so long. 
 using string.maketrans() is recommended. now apply on the url
 Is that the answer because it does not solve the problem when I apply it 
 to the url.

Not to the whole url! Then it wouldn't be a url anymore! Just to ___.html 
part that is three letters long. And generally you shouldn't post answers to 
the challenges on public lists, because they can spoil it for others wanting 
to take the challenge.

JS 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python CLI parser

2007-12-21 Thread bob gailer
Martin Marcher wrote:
 Hello,

 could you have a short review of my CLI package.
   
.bz2???  What does that extension mean? (For us Windows folk). Or could 
you attach a simple zip file?

[snip]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python CLI parser

2007-12-21 Thread tezlo
Martin Marcher [EMAIL PROTECTED] wrote:
 Hello,
 
 could you have a short review of my CLI package.

Hi,
it looks alright, it's really rather tiny. For one I could do with
spaces between functions for the sake of readability. And it would
make more sense to check the callback for being a callable once - while
registering it, instead of every time it's triggered. It's good to
program defensively, especially in a dynamic language like python,
where you can hardly stop anyone (yourself) from stuffing the dict
with uncallable garbage. But in this case, you deserve the exception as
it's up to you, the programmer, to register the commands. The check
should not be necessary if you write your program correctly.

As for CTRL+D, it fires an EOF. The manual for readline() says:
 A trailing newline character is kept in the string
 An empty string is returned when EOF is encountered immediately.
but you strip() the command (in two places) and lose the chance of
checking for that very case. Hope this helps.

tezlo
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Regular Expression

2007-12-21 Thread Que Prime
I need to pull the highligted data from a similar file and can't seem to get
my script to work:

Script:
import re
infile = open(filter.txt,r)
outfile = open(out.txt,w)
patt = re.compile(r~02([\d{10}]))
for line in infile:
  m = patt.match(line)
  if m:
outfile.write(%s\n)
infile.close()
outfile.close()


File:
200~02001491~05070
200~02001777~05070
200~02001995~05090
200~02002609~05090
200~02002789~05070
200~012~02004169~0
200~02004247~05090
200~02008623~05090
200~02010957~05090
200~02 011479~05090
200~0199~02001237~
200~02011600~05090
200~012~02 022305~0
200~02023546~05090
200~02025427~05090
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Regular Expression

2007-12-21 Thread Michael H. Goldwasser

Que,

I haven't tested the script, but please note that patt.match(line)
will only succeed when the pattern is at the start of the line.  Use
patt.search(line) if you want to find the pattern anywhere within the
line.

Based on your desired highlight, you might want to use the pattern,
patt = re.compile(r~02(\d*)~)

Also, your outfile.write command below doesn't provide any substitute
for %s.   Presumably you mean outfile.write(%s\n % m.group(1)) .

Good luck,
Michael

On Friday December 21, 2007, Que Prime wrote: 

I need to pull the highligted data from a similar file and can't seem to 
 get
my script to work:

Script:
import re
infile = open(filter.txt,r)
outfile = open(out.txt,w)
patt = re.compile(r~02([\d{10}]))
for line in infile:
  m = patt.match(line)
  if m:
outfile.write(%s\n)
infile.close()
outfile.close()


File:
200~02001491~05070
200~02001777~05070
200~02001995~05090
200~02002609~05090
200~02002789~05070
200~012~02004169~0
200~02004247~05090
200~02008623~05090
200~02010957~05090
200~02 011479~05090
200~0199~02001237~
200~02011600~05090
200~012~02 022305~0
200~02023546~05090
200~02025427~05090


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Regular Expression

2007-12-21 Thread Tiger12506
I need to pull the highligted data from a similar file and can't seem to 
get
 my script to work:

 Script:
 import re
 infile = open(filter.txt,r)
 outfile = open(out.txt,w)
 patt = re.compile(r~02([\d{10}]))

You have to allow for the characters at the beginning and end too.
Try this.
re.compile(r.*~02(\d{10})~.*)

Also outfile.write(%s\n) literally writes %s\n
You need this I believe

outfile.write(%s\n % m.group(1))


 for line in infile:
  m = patt.match(line)
  if m:
outfile.write(%s\n)
 infile.close()
 outfile.close()


 File:
 200~02001491~05070
 200~02001777~05070
 200~02001995~05090
 200~02002609~05090
 200~02002789~05070
 200~012~02004169~0
 200~02004247~05090
 200~02008623~05090
 200~02010957~05090
 200~02 011479~05090
 200~0199~02001237~
 200~02011600~05090
 200~012~02 022305~0
 200~02023546~05090
 200~02025427~05090






 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor
 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Regular Expression

2007-12-21 Thread Michael Langford
You need to pass a parameter to the string in the following line:

outfile.write(%s\n % m.string[m.start():m.end()])

And you need to use m.search, not m.match in the line where you're
actually apply the expression to the string

 m = patt.search(line)

   --Michael

On 12/21/07, Que Prime [EMAIL PROTECTED] wrote:


 I need to pull the highligted data from a similar file and can't seem to get
 my script to work:

 Script:
 import re
 infile = open(filter.txt,r)
 outfile = open(out.txt,w)
 patt = re.compile(r~02([\d{10}]))
 for line in infile:
   m = patt.match(line)
   if m:
 outfile.write(%s\n)
 infile.close()
 outfile.close()


 File:
 200~02001491~05070
 200~02001777~05070
 200~02001995~05090
 200~02002609~05090
 200~02002789~05070
 200~012~02004169~0
  200~02004247~05090
 200~02008623~05090
 200~02010957~05090
 200~02 011479~05090
 200~0199~02001237~
 200~02011600~05090
 200~012~02 022305~0
 200~02023546~05090
 200~02025427~05090


 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor




-- 
Michael Langford
Phone: 404-386-0495
Consulting: http://www.RowdyLabs.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor