Re: [Tutor] use the data None

2012-06-04 Thread Tehn Yit Chin
Thanks for the quick answers.

The potential for the variable not to exists is when I am using the
optparser module, and I want to check if a particular parameter was passed
in or not. If the parameter was not passed in, then the variable would not
exists. Eg

If I call a python script is expecting a parameter "param1" but I failed to
passed it via the command line, I would do the following check

(options, args)=parser.parse_args()
if options.param1 != None:
 param1 = int(options.param1 )
else:
 param1 = 30

By the way, please excuse the way I am coding, I come from a C background.

I think I shall try the catch method.

Thanks!

On Mon, Jun 4, 2012 at 3:09 AM, Alan Gauld wrote:

> On 04/06/12 01:39, Alan Gauld wrote:
>
>  for var in (a,b,c):
>>if not var:
>>   print var.__name__, ' is empty or false'
>>
>
> Oops, that won't work. __name__ is not an attribute
> of object, which I thought it was...
>
> But hopefully the intention was clear.
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor
>



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


Re: [Tutor] use the data None

2012-06-04 Thread Sander Sweers
On 4 June 2012 12:14, Tehn Yit Chin  wrote:
> The potential for the variable not to exists is when I am using the
> optparser module, and I want to check if a particular parameter was passed
> in or not. If the parameter was not passed in, then the variable would not
> exists. Eg

Optparse will always create the variable, it may contain None.

> If I call a python script is expecting a parameter "param1" but I failed to
> passed it via the command line, I would do the following check
>
> (options, args)=parser.parse_args()
> if options.param1 != None:
>  param1 = int(options.param1 )
> else:
>  param1 = 30
>
> By the way, please excuse the way I am coding, I come from a C background.

The important part of you code is missing. You should show how you
create the parser (with the options etc).

The optparse module can provide a default value, did you know this?
See the online documentation on [1]. It shows an example of this right
at the beginning.

Greets
Sander
[1] http://docs.python.org/library/optparse.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] packets_USB_python

2012-06-04 Thread BILAL Mustapha

Hello,

 I am beginner with python and I recently started to use it in order to 
achieve a small part of something I am working on.


 I have 2 processes (process 1 and process 2). I am wondering if you 
can provide me with some example or sample code of how I can do the 
following:


 - Process 2 receives icmpv6 (or any packet) from process1 and 
retransmit it to a serial link (USB)
 - Process 2 receives icmpv6 (or any packet) from the serial link (USB) 
and restransmit it to process 1.


 I had tried to write some code to, at least, ping but apparently I am 
missing something.


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


Re: [Tutor] packets_USB_python

2012-06-04 Thread Alan Gauld

On 04/06/12 14:58, BILAL Mustapha wrote:


- Process 2 receives icmpv6 (or any packet) from process1 and retransmit
it to a serial link (USB)
- Process 2 receives icmpv6 (or any packet) from the serial link (USB)
and restransmit it to process 1.


Oddly, Python does not have ICMP support in its standard library however 
there is an icmpv6 module on Activestate:


http://code.activestate.com/recipes/409689-icmplib-library-for-creating-and-reading-icmp-pack/

And there is also a module for reading/writing to usb ports (pyusb)...

http://pyusb.sourceforge.net/docs/1.0/tutorial.html

hth,

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] packets_USB_python

2012-06-04 Thread Emile van Sebille

On 6/4/2012 6:58 AM BILAL Mustapha said...

Hello,

I am beginner with python and I recently started to use it in order to
achieve a small part of something I am working on.

I have 2 processes (process 1 and process 2). I am wondering if you can
provide me with some example or sample code of how I can do the following:



Interprocess communications may be a bit advanced for this forum.  Look 
at http://wiki.python.org/moin/ParallelProcessing as you're likely to 
find something appropriate there.


HTH,

Emile





- Process 2 receives icmpv6 (or any packet) from process1 and retransmit
it to a serial link (USB)
- Process 2 receives icmpv6 (or any packet) from the serial link (USB)
and restransmit it to process 1.

I had tried to write some code to, at least, ping but apparently I am
missing something.

Many thanks
___
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] packets_USB_python

2012-06-04 Thread BILAL Mustapha

Le 04/06/2012 16:10, Alan Gauld a écrit :

On 04/06/12 14:58, BILAL Mustapha wrote:


- Process 2 receives icmpv6 (or any packet) from process1 and retransmit
it to a serial link (USB)
- Process 2 receives icmpv6 (or any packet) from the serial link (USB)
and restransmit it to process 1.


Oddly, Python does not have ICMP support in its standard library 
however there is an icmpv6 module on Activestate:


http://code.activestate.com/recipes/409689-icmplib-library-for-creating-and-reading-icmp-pack/ 



And there is also a module for reading/writing to usb ports (pyusb)...

http://pyusb.sourceforge.net/docs/1.0/tutorial.html

hth,


Thank you for your reply and for the useful links.

However Can't I use the popen() to lunch the process1 and write on its 
standard input? same thing for the process1 when it wants to sends 
infos(or packets) to process2 then it will use its standard output!


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


[Tutor] Web Questionnaire

2012-06-04 Thread Akeria Timothy
Hello All,

I am still new to learning Python and I wanted to know if anyone knew of a
script out there that would allow users to answer three basic questions,
hit submit and send that information to an excel spreadsheet?

So, I would want them to submit the following information:

Name:
Dept:
Software needed:
Semester requesting software for:

I work for a college and I wanted to streamline the software requests for
the school year.

Is this a basic script? I have started my script but I know it will
probably take me longer to write it so I figured I would ask if there was
something out there that I could just modify.


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


Re: [Tutor] Web Questionnaire

2012-06-04 Thread Joel Goldstick
On Mon, Jun 4, 2012 at 11:12 AM, Akeria Timothy  wrote:
> Hello All,
>
> I am still new to learning Python and I wanted to know if anyone knew of a
> script out there that would allow users to answer three basic questions, hit
> submit and send that information to an excel spreadsheet?
>
> So, I would want them to submit the following information:
>
> Name:
> Dept:
> Software needed:
> Semester requesting software for:
>
> I work for a college and I wanted to streamline the software requests for
> the school year.
>
> Is this a basic script? I have started my script but I know it will probably
> take me longer to write it so I figured I would ask if there was something
> out there that I could just modify.
>
>
> Thanks in advance
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
I'm not sure this is a 'python tutor' question.  You would need to
have a website that presumable limits access to certain people so that
anyone couldn't make a request.  Django could do that for you out of
the box more or less, but then you would have to deploy it. So, its
not just a small python script, but a website you would need to build.
 Are you up to that yet?

If you are thinking up useful projects to expand your python skills,
perhaps publishing an email box for requests would be easier.  You
could read the emails and enter the data in a simple command line
program you could write in python to added data in csv format to a
file.  This file could be viewed in excel.

Such a project would help you learn about csv module, and how to
request data from a user. -- both useful things to learn


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


Re: [Tutor] Web Questionnaire

2012-06-04 Thread James Reynolds
I would say start using django.

The best way to learn is by doing.

This will let you learn about databases, servers, webapps, and you can get
some functionality out of it. Just start going through the django tutorial.
On Jun 4, 2012 11:57 AM, "Joel Goldstick"  wrote:

> On Mon, Jun 4, 2012 at 11:12 AM, Akeria Timothy 
> wrote:
> > Hello All,
> >
> > I am still new to learning Python and I wanted to know if anyone knew of
> a
> > script out there that would allow users to answer three basic questions,
> hit
> > submit and send that information to an excel spreadsheet?
> >
> > So, I would want them to submit the following information:
> >
> > Name:
> > Dept:
> > Software needed:
> > Semester requesting software for:
> >
> > I work for a college and I wanted to streamline the software requests for
> > the school year.
> >
> > Is this a basic script? I have started my script but I know it will
> probably
> > take me longer to write it so I figured I would ask if there was
> something
> > out there that I could just modify.
> >
> >
> > Thanks in advance
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
> >
> I'm not sure this is a 'python tutor' question.  You would need to
> have a website that presumable limits access to certain people so that
> anyone couldn't make a request.  Django could do that for you out of
> the box more or less, but then you would have to deploy it. So, its
> not just a small python script, but a website you would need to build.
>  Are you up to that yet?
>
> If you are thinking up useful projects to expand your python skills,
> perhaps publishing an email box for requests would be easier.  You
> could read the emails and enter the data in a simple command line
> program you could write in python to added data in csv format to a
> file.  This file could be viewed in excel.
>
> Such a project would help you learn about csv module, and how to
> request data from a user. -- both useful things to learn
>
>
> --
> Joel Goldstick
> ___
> 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] Web Questionnaire

2012-06-04 Thread Akeria Timothy
Thanks Joel the email box suggestion is a good one.

I guess I'm lookingfor an easier way to get the information from faculty
members on my campus. My boss currently just sends an email out to them.
The error with this is that they reply with answers not related to what the
email asks.
On Jun 4, 2012 11:56 AM, "Joel Goldstick"  wrote:

> On Mon, Jun 4, 2012 at 11:12 AM, Akeria Timothy 
> wrote:
> > Hello All,
> >
> > I am still new to learning Python and I wanted to know if anyone knew of
> a
> > script out there that would allow users to answer three basic questions,
> hit
> > submit and send that information to an excel spreadsheet?
> >
> > So, I would want them to submit the following information:
> >
> > Name:
> > Dept:
> > Software needed:
> > Semester requesting software for:
> >
> > I work for a college and I wanted to streamline the software requests for
> > the school year.
> >
> > Is this a basic script? I have started my script but I know it will
> probably
> > take me longer to write it so I figured I would ask if there was
> something
> > out there that I could just modify.
> >
> >
> > Thanks in advance
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
> >
> I'm not sure this is a 'python tutor' question.  You would need to
> have a website that presumable limits access to certain people so that
> anyone couldn't make a request.  Django could do that for you out of
> the box more or less, but then you would have to deploy it. So, its
> not just a small python script, but a website you would need to build.
>  Are you up to that yet?
>
> If you are thinking up useful projects to expand your python skills,
> perhaps publishing an email box for requests would be easier.  You
> could read the emails and enter the data in a simple command line
> program you could write in python to added data in csv format to a
> file.  This file could be viewed in excel.
>
> Such a project would help you learn about csv module, and how to
> request data from a user. -- both useful things to learn
>
>
> --
> Joel Goldstick
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] suggestions to improve design

2012-06-04 Thread Justin Straube
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hello Tutors,

I've written a script to use within XChat (IRC client) and everything is
working without issue. The script is a little tool to give an emote
command and a handful of general pre written actions.

As it is now, the script works. But I've got maybe a dozen emotes in
there, using if/elif loops to check against a list of emotes and
format a string for display in the channel.

But, I also have another dictionary containing duplicate values with
text placeholders where a %s would be substituted.

I feel that, as the list of available emotes grows, the script will
suffer from a poor design. I have thought about pickling or using a file
to store the dict or loops, but that only seems like a bandage and
there may be a performance issue with potentially hundreds of loops to
check through.

Ok, so I have posted my script at
http://www.baked-potato.us/files/2ndthat.py

My question is, would anybody please take a look and offer suggestions
on what I may do to improve this script?

Thank you,
Justin
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.16 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJPzNYQAAoJEBXz28t2j4R5cmYIAIVIQMJI7HshaV0WqmbUKp1U
+vFdLbD52JHs+x4dUwq6DBWdAllauxkm0GW6PGYhHefQZrzRrplTG37Oj+C6czvT
pHT6mI1AwXdrQIQab6D0JEPkqIw9kuQormNrUynxwZFSU7M/Z1qmBv0twikwDUVD
R3hClBeuVMydLk2DhIuPpgqEO/6ljkN8tK6El5+1vIQFsVRizEX2HVeco7oMz/9x
ePedVpEfW4cGpRcFz2gnthzLawoPPmxKc3fTTq29za/tR8eqvUxXY4vjxWWeOr/+
N97Yfdglo1pa4Kir/Ukd+678R/WHZzrqZVRTa4fRZC17cSOU1Pd96L2cqwOCqzs=
=0zEs
-END PGP SIGNATURE-


0x768F8479.asc
Description: application/pgp-keys
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Joining all strings in stringList into one string

2012-06-04 Thread Prasad, Ramit
> But more importantly, some years ago (Python 2.4, about 8 years ago?) the
> Python developers found a really neat trick that they can do to optimize
> string concatenation so it doesn't need to repeatedly copy characters over
> and
> over and over again. I won't go into details, but the thing is, this trick
> works well enough that repeated concatenation is about as fast as the join
> method MOST of the time.

I would like to learn a bit more about the trick if you have a 
reference handy. I have no intention of using it, but it sounds 
interesting and might teach me more about Python internals.


Ramit


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

--

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Parser/pgen] Error 1

2012-06-04 Thread Prasad, Ramit
> > I was following instructions on this link:
> >
> > http://eli.thegreenplace.net/2011/10/10/installing-python-2-7-on-ubuntu/
> >
> >
> > Thank you all so much I cannot wait to learn from you guys :)

> Not sure about your error.  However, python is pre installed in
> ubuntu.  go to a shell and type python.  See if you get the python
> shell

The Ubuntu repository should have most versions you would want
if you decide you need a different version than the system default.
More of a Debian user myself so I would do something like the following
to see the different versions (just a guess since I am away from
my Debian machine).
 
`apt-cache search python | grep ^python`

I grep for ^python because there are probably a lot of python
package libraries that are unrelated to core python, but useful
for other applications.

Ramit


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

--


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Parser/pgen] Error 1

2012-06-04 Thread Alan Gauld

On 04/06/12 17:18, Prasad, Ramit wrote:


The Ubuntu repository should have most versions you would want
if you decide you need a different version than the system default.

`apt-cache search python | grep ^python`


apt-cache search python | grep ^python[1-9]


Works on Ubuntu too. But when I try it (10.4 LTS) it only
shows versions 2.6, 3 and 3.1. Not 2.7...

But the easier way is to use the Ubuntu Software centre. Look under
Developer Tools and there is a whole section on Python...

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] suggestions to improve design

2012-06-04 Thread Prasad, Ramit
> I've written a script to use within XChat (IRC client) and everything is
> working without issue. The script is a little tool to give an emote
> command and a handful of general pre written actions.
> 
> As it is now, the script works. But I've got maybe a dozen emotes in
> there, using if/elif loops to check against a list of emotes and
> format a string for display in the channel.
> 
> But, I also have another dictionary containing duplicate values with
> text placeholders where a %s would be substituted.
> 
> I feel that, as the list of available emotes grows, the script will
> suffer from a poor design. I have thought about pickling or using a file
> to store the dict or loops, but that only seems like a bandage and
> there may be a performance issue with potentially hundreds of loops to
> check through.
> 
> Ok, so I have posted my script at
> http://www.baked-potato.us/files/2ndthat.py
> 
> My question is, would anybody please take a look and offer suggestions
> on what I may do to improve this script?

Unless the script gets a *very* large list of emotes or you are on
an older machine I doubt that you will really see any performance
issues. That being said, my comments are below and other tutors
can correct anything I missed or said incorrectly. I like the 
presence of your documentation, kudos!

Why use a class for storing the 'tions' and dict directly from
the module?

tions = { [snip] }

I also think get_emote should not be passed the entire argv, 
it should be passed only the arguments it needs so I would change
the call to

def emote(argv):
emote = argv[1]
if emote in tions: # look at dictionary, no need to pull keys manually  
emstring = get_emote(emote, argv[2:]) # pass only arguments

# print a generic message to the channel displaying the emote string
#xchat.emit_print("Generic Message", nick, emstring)
xchat.command("me %s" % (emstring))

def get_emote( e, args ):
if e in tions:
if '%s' in tions[e]:
return tions[e] % tuple(args) 
# will error here if not the correct number of variables
# in args; might want to catch and then return an error string
else
return tions[e]
else:
return 'Not an understood emote'


def list_em():
print "There are %s emotes available." % (len(tions))
print "Usage: /em \002<$emote>\002 - user supplied values are shown as 
\002<$bold>\002.\n"

for key,value in tions.iteritems(): 
print "Emote: %s - %s" % (key, value)


As a general note, you should use docstrings instead of comments 
above the function.

CHANGE

# show function - displays a single requested emote 
def show(s):

TO 

def show(s):
'displays a single requested emote' # single line docstring

OR

def show(s):
   ''' multi
   line 
   docstring
   '''


Ramit


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

--
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Parser/pgen] Error 1

2012-06-04 Thread Walter Prins
Hi,

On 4 June 2012 18:27, Alan Gauld  wrote:
> On 04/06/12 17:18, Prasad, Ramit wrote:
>
> apt-cache search python | grep ^python[1-9]
>
>> Works on Ubuntu too. But when I try it (10.4 LTS) it only
> shows versions 2.6, 3 and 3.1. Not 2.7...

Just to add/point out for the sake of the original poster: The
original web page referenced was about installing Python 2.7 on Ubuntu
10.04, which didn't include and didn't have Python 2.7 available from
package repositories, which is why the author of the web page had to
install it manually.  However, the original question poster is in fact
using Ubuntu 12.04, which does come with Python 2.7 included  and also
likely has a few other version available in the package repositories.
So the web page is actually not applicable to the original poster,
unless he's also trying to install a version of Python not available
in the 12.04 package repositories.  To the original poster: What
version of Python are you trying to install?

Best regards,

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


Re: [Tutor] Beginner

2012-06-04 Thread Walter Prins
Hello,

On 4 June 2012 19:50, dispatc...@live.com  wrote:
> I am new to the python idle. I am a little confused on the GUI section on
> where to write it.

I think that's perhaps an understatement. 

>> The tutorial I am using says not to write GUI in the idle section so I have
> been using the python shell to write the GUI app.

I'm pretty sure the tutorial didn't instruct you to actually use the
shell to write GUI (or any kind of) applications... (By the way, you
didn't mention what tutorial you're using?)

> This is not to productive
> for me cause after I save it as .pyw I am unable to open it to edit or add
> to the code. I have to start over in another shell.

Yes, well, it's a bad idea, and the downsides you mention is true of
writing any Python application, not just GUI ones.  You should use the
shell to experiment, test, peform introspection, read documentation,
etc. etc, not to actually develop your applications... that's what
editors and IDE's are for.

> My question is working with Tkinter in order to run it and being able to see
> step by step progress and maintain the ability to edit or add as I go where
> do I need to code it what program?

TkInter apps can sometimes not play nice with Idle when run from
within Idle for various reasons which I've now forgotten (partly
because Idle is itself written in TkInter I think), but I seem to also
vaguely recall that this is somewhat less of a problem nowadays than
it used to be and/or the issues can be avoided with a bit of care.
(I'm sure the others on the list will correct me if I'm imagining
things and/or elaborate on this.)  So, if your app is simple, and
certainly while you're learning you might want to use Idle despite
what tutorial says. At worst, you can avoid issues by simply running
your application manually e.g. apart from Idle. (Notwithstanding your
next point.)

> As well once I have saved the code as .pyw when I go to the location to open
> and run it it does nothing how do I run it after its saved and completed.

Well when done correctly it should work.  It's impossible to tell
without more information about what's really going on why it's "doing
nothing."  There may be a problem with your program, there might be a
problem with your Python setup, there may be a problem with your
operating system environment, etc. etc.  Anyway, if you open your .pyw
file with say Windows notepad or any other text editor (or, indeed,
Idle), what does it contain?

> I am running winows 7 thanks

What version of Python?  I recommend the Activestate distribution of
Python on Windows these days as their installer does several
convenience steps automatically that the official Python distributions
do not do and provides several tools useful on Windows as well.  You
might have a look at it/switch if you're not using it yet:
http://www.activestate.com/activepython/downloads

Hope that helps,

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


Re: [Tutor] Beginner

2012-06-04 Thread Alan Gauld

On 04/06/12 19:50, dispatc...@live.com wrote:


The tutorial I am using says not to write GUI in the idle section


I suspect it only says not to *run* it in IDLE. Writing it
in IDLE is fine. But sometimes running Tkinter apps in Idle causes 
strange behaviour.  So save the file then run it from

Windows Explorer, eg. by double clicking the file.


have been using the python shell to write the GUI app.


The Python shell is designed for testing and exploring not for writing 
apps. Use a text editor (Idle or something else). On windows I tended to 
use vim or Scite or occasionally Eclipse with PyDev plugin.



As well once I have saved the code as .pyw when I go to the location to
open and run it it does nothing how do I run it after its saved and
completed.


That's probably due to a coding error.
Write a short Tkinter program that exhibits the problem and post it 
here. We can then try to advise you.


HTH

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] use the data None

2012-06-04 Thread Dave Angel
On 06/04/2012 06:14 AM, Tehn Yit Chin wrote:
> Thanks for the quick answers.
>
> The potential for the variable not to exists is when I am using the
> optparser module, and I want to check if a particular parameter was passed
> in or not. If the parameter was not passed in, then the variable would not
> exists. Eg
>
> If I call a python script is expecting a parameter "param1" but I failed to
> passed it via the command line, I would do the following check
>
> (options, args)=parser.parse_args()
> if options.param1 != None:
>  param1 = int(options.param1 )
> else:
>  param1 = 30
>
> By the way, please excuse the way I am coding, I come from a C background.
>
> I think I shall try the catch method.
>
> Thanks!
>
> On Mon, Jun 4, 2012 at 3:09 AM, Alan Gauld wrote:
>
>> On 04/06/12 01:39, Alan Gauld wrote:
>>
>>  for var in (a,b,c):
>>>if not var:
>>>   print var.__name__, ' is empty or false'
>>>
>> Oops, that won't work. __name__ is not an attribute
>> of object, which I thought it was...
>>
>> But hopefully the intention was clear.
>>
>>
>> --
>> Alan G
>> Author of the Learn to Program web site
>> http://www.alan-g.me.uk/
>>
>> __**_
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/**mailman/listinfo/tutor
>>
>
Gosh, you said the variable might not exist.  But then you're using the
code   options.param1  where param1 is an attribute, not a variable in
any sense of the word.

If you have an *attribute* that may or may not exist, you can use
getattr() function on it, and even specify your own default.

Of course, if the stuff is coming from some argument parsing logic, it
probably already handles this for you, and this is all besides the point.



-- 

DaveA

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


Re: [Tutor] suggestions to improve design

2012-06-04 Thread Justin Straube
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 06/04/2012 11:28 AM, Prasad, Ramit wrote:
> Unless the script gets a *very* large list of emotes or you are on 
> an older machine I doubt that you will really see any performance 
> issues. That being said, my comments are below and other tutors

Thank you for your time, Ramit.

> can correct anything I missed or said incorrectly. I like the 
> presence of your documentation, kudos!

As a hobbyist, I can afford the time to document. I also find that
even with code I wrote, the documentation helps me understand better,
and find areas that need more work.

> Why use a class for storing the 'tions' and dict directly from the
> module?
> 
> tions = { [snip] }

When I started, I was unsure what else I would be putting in the class
Emo. After I got going, I was unsure about changing that, if the
design needed adjusting and it would be used further. Before I do to
much more for this, I am going to remove the class and just use the
dictionary, with a better name.

Thank you for your other ideas. Ill work over this and also clean up
my comments.

Justin


> I also think get_emote should not be passed the entire argv, it
> should be passed only the arguments it needs so I would change the
> call to
> 
> def emote(argv): emote = argv[1] if emote in tions: # look at
> dictionary, no need to pull keys manually emstring =
> get_emote(emote, argv[2:]) # pass only arguments
> 
> # print a generic message to the channel displaying the emote
> string #xchat.emit_print("Generic Message", nick, emstring) 
> xchat.command("me %s" % (emstring))
> 
> def get_emote( e, args ): if e in tions: if '%s' in tions[e]: 
> return tions[e] % tuple(args) # will error here if not the correct
> number of variables # in args; might want to catch and then return
> an error string else return tions[e] else: return 'Not an
> understood emote'
> 
> 
> def list_em(): print "There are %s emotes available." %
> (len(tions)) print "Usage: /em \002<$emote>\002 - user supplied
> values are shown as \002<$bold>\002.\n"
> 
> for key,value in tions.iteritems(): print "Emote: %s - %s" % (key,
> value)
> 
> 
> As a general note, you should use docstrings instead of comments 
> above the function.
> 
> CHANGE
> 
> # show function - displays a single requested emote def show(s):
> 
> 
> TO
> 
> def show(s): 'displays a single requested emote' # single line
> docstring
> 
> OR
> 
> def show(s): ''' multi line docstring '''
> 
> 
> Ramit
> 
> 
> Ramit Prasad | JPMorgan Chase Investment Bank | Currencies
> Technology 712 Main Street | Houston, TX 77002 work phone: 713 -
> 216 - 5423

-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.16 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJPzYq7AAoJEBXz28t2j4R5MT4H/2ILvS33kQmW5r8sNyeszoir
p5BNJOOEcEpc9Th41+12hXrP1Jir0COUur1HKqoom6Ufx07FuYPhiQ2MOC7W43EZ
I9m8/F0b/DkxLBBwg4CL+tfTAhIZ9R2/rfKxQ8GQSN4Yn29X6WGrP/uK9TRlHERq
ucb3tYPOp8b/zMujILVjndkqozupqNTrGZVBe8F8tphcnlv6ScZHjDRsaK898SbL
mcK/Ua45XVpaGpunIV8Um03hVf+UZwwvat348vOE8fgsOyywXaZc0oHsVr6G41os
zsQXR2/3CJA88ZVqJzRKmwdHJ2xuPsNWnrTuxplsHnsNWuHMHBHmnPj+HC9Gnsw=
=BPDI
-END PGP SIGNATURE-


0x768F8479.asc
Description: application/pgp-keys
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor