Re: [Tutor] how to temporarily disable a function

2011-07-28 Thread Alan Gauld

Pete O'Connell wrote:

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)


simply change the binding of widget to function.
Then change it back to re-enable it.

You don't say which GUI framework you are using so we can't give sample 
code but most GUIs offer a way to dynamically modify event bindings.


HTH,

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


Re: [Tutor] how to temporarily disable a function

2011-07-28 Thread Dave Angel

On 07/27/2011 09:58 PM, Pete O'Connell wrote:

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


Presumably that function is defined in a different module than the one 
you're going to "disable" it from.  So, what you're attempting is 
commonly called "monkeypatching."


Let's say the module is   snapper  (in a file snapper.py).

All you probably need is to substitute another do-nothing function in 
its place.


import snapper

def donothing():
return

snapper.theAutoplaceSnap = donothing

If it will need to be restored later, you can copy it to a variable in 
your own module, and then copy it back later.


--

DaveA

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


Re: [Tutor] how to temporarily disable a function

2011-07-28 Thread Peter Otten
Pete O'Connell wrote:

> 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.

http://docs.thefoundry.co.uk/nuke/63/pythondevguide/callbacks.html#onusercreate

suggests that you can remove the callback with

nuke.removeOnUserCreate(theAutoplaceSnap)

You can later add it back with

nuke.addOnUserCreate(theAutoplaceSnap)

like in the code snippet you provided. If the add/removeOnUserCreate() calls 
occur in another module than the one theAutplaceSnap() is defined in you 
need to import that first and use qualified names (e. g. 
some_module.theAutoplaceSnap).


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


[Tutor] Is it bad practise to write __all__ like that

2011-07-28 Thread Karim


Hello,

__all__ = 'api db input output tcl'.split()

or

__all__ = """
   api
   db
   input
   output
   tcl
   """.split()

for lazy boy ;o). It is readable as well.
What do you think?

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


Re: [Tutor] Is it bad practise to write __all__ like that

2011-07-28 Thread Steven D'Aprano

Karim wrote:


Hello,

__all__ = 'api db input output tcl'.split()


Yes, it's lazy, no it is not bad practice. I wouldn't do it myself, but 
I wouldn't object if somebody else did it.




--
Steven

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


Re: [Tutor] python Module for Windows Active Directory

2011-07-28 Thread Tim Golden

On 28/07/2011 07:28, qbits...@gmail.com wrote:

Hi,

Which is the best package/module in Python to work with Windows Active
Directory?

I may need to create multiple OUs, set different users and computers and
fill their individual attributes. Later i may need to modify/delete and
then may need to check them for its availability.


You could try my active_directory module:

  http://timgolden.me.uk/python/active_directory.html

although there's a much-improved version in development
(and actively used here at work). If you're interested,
look at:

  http://svn.timgolden.me.uk/active_directory/branches/rework/

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


[Tutor] KeyError?

2011-07-28 Thread Shwinn Ricci
I have an excel file that I am reading cell values from and putting them
into a dictionary. the dictionary looks like this:

scafPositions = {position[j]: direction[j]}

where position[j] is exclusively floating/numerical values and direction[j]
is exclusively strings.

When I try to find whether a test value val is in the array of positions,
and then try to look its direction up with ScafPositions[val], I get a
KeyError. Is this because my data isn't standalone numbers, but numbers that
are calculated based off other cells? Or can I not test for val?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] KeyError?

2011-07-28 Thread James Reynolds
On Thu, Jul 28, 2011 at 11:50 AM, Shwinn Ricci  wrote:

> I have an excel file that I am reading cell values from and putting them
> into a dictionary. the dictionary looks like this:
>
> scafPositions = {position[j]: direction[j]}
>
> where position[j] is exclusively floating/numerical values and direction[j]
> is exclusively strings.
>
> When I try to find whether a test value val is in the array of positions,
> and then try to look its direction up with ScafPositions[val], I get a
> KeyError. Is this because my data isn't standalone numbers, but numbers that
> are calculated based off other cells? Or can I not test for val?
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>

Did you try printing the contents of scafPositions to see what it contains,
first?

Also, a traceback is helpful.

As far as introspection, which module are you using to read the excel files?
There's at least two that I know of.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] KeyError?

2011-07-28 Thread Walter Prins
On 28 July 2011 16:50, Shwinn Ricci  wrote:

> I have an excel file that I am reading cell values from and putting them
> into a dictionary. the dictionary looks like this:
>
> scafPositions = {position[j]: direction[j]}
>
> where position[j] is exclusively floating/numerical values and direction[j]
> is exclusively strings.
>
> When I try to find whether a test value val is in the array of positions,
> and then try to look its direction up with ScafPositions[val], I get a
> KeyError. Is this because my data isn't standalone numbers, but numbers that
> are calculated based off other cells? Or can I not test for val?
>

http://wiki.python.org/moin/KeyError

I quote:
"Python raises a *KeyError* whenever a dict() object is requested (using the
format a = adict[key]) and the key is not in the dictionary. If you don't
want to have an exception but would rather a default value used instead, you
can use the get() method: "

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


Re: [Tutor] KeyError?

2011-07-28 Thread Prasad, Ramit
From: tutor-bounces+ramit.prasad=jpmchase@python.org 
[mailto:tutor-bounces+ramit.prasad=jpmchase@python.org] On Behalf Of Shwinn 
Ricci
Sent: Thursday, July 28, 2011 10:51 AM
To: tutor@python.org
Subject: [Tutor] KeyError?

I have an excel file that I am reading cell values from and putting them into a 
dictionary. the dictionary looks like this:

scafPositions = {position[j]: direction[j]}

where position[j] is exclusively floating/numerical values and direction[j] is 
exclusively strings.

When I try to find whether a test value val is in the array of positions, and 
then try to look its direction up with ScafPositions[val], I get a KeyError. Is 
this because my data isn't standalone numbers, but numbers that are calculated 
based off other cells? Or can I not test for val?
==

Your problem is probably that you are reassigning a new dictionary to the name 
scafPositions each time instead of updating it. You should have something like 
the following.

scafPositions = {}

#loop structure here:
#do stuff
scafPositions[ position[j] ] = direction[j]



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] KeyError?

2011-07-28 Thread James Reynolds
On Thu, Jul 28, 2011 at 12:11 PM, Prasad, Ramit
wrote:

> *From:* tutor-bounces+ramit.prasad=jpmchase@python.org [mailto:
> tutor-bounces+ramit.prasad=jpmchase@python.org] *On Behalf Of *Shwinn
> Ricci
> *Sent:* Thursday, July 28, 2011 10:51 AM
> *To:* tutor@python.org
> *Subject:* [Tutor] KeyError?
>
> ** **
>
> I have an excel file that I am reading cell values from and putting them
> into a dictionary. the dictionary looks like this:
>
> scafPositions = {position[j]: direction[j]}
>
> where position[j] is exclusively floating/numerical values and direction[j]
> is exclusively strings.
>
> When I try to find whether a test value val is in the array of positions,
> and then try to look its direction up with ScafPositions[val], I get a
> KeyError. Is this because my data isn't standalone numbers, but numbers that
> are calculated based off other cells? Or can I not test for val?
>
> ==
>
> ** **
>
> Your problem is probably that you are reassigning a new dictionary to the
> name scafPositions each time instead of updating it. You should have
> something like the following.
>
> ** **
>
> scafPositions = {}
>
> ** **
>
> #loop structure here:
>
> #do stuff
>
> scafPositions[ position[j] ] = direction[j]
>
>
>



Or it could be it's not introspecting the formula within excel and his key
is the string "=A1*sheet2!$B$1"or it could be he's looking for a float / int
when in reality it's a string (because it must be converted explicitly).

Without a traceback and the code, it's hard to know for sure.

My guess is leading towards introspection.

As far as printing the contents, once you create your dict with all the data
just use the print statement / function depending on your version of python

print scafPositions or print(scafPositions)

You could loop through it as well

for key, value in scafPositions.items():
print key, value

This will give you an idea of what is in the dict.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to temporarily disable a function

2011-07-28 Thread Christopher King
On Thu, Jul 28, 2011 at 5:08 AM, Peter Otten <__pete...@web.de> wrote:

> Pete O'Connell wrote:
>
> > Hi I was wondering if there is a way to disable a function.
>
>
You could use this decorator:
class Disabler(object):
def __init__(self, old_function):
self.__old = old_function
self.enabled=True
def __call__(self, *arg, **kwd):
if enabled: return self.__old(*arg, **kwd)
def enable(self): self.enabled = True
def disable(self): self.enabled=False


> ___
> 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 :p:

2011-07-28 Thread Christopher King
On Wed, Jul 27, 2011 at 9:11 PM, Thomas C. Hicks  wrote:

> On Wed, 27 Jul 2011 20:16:31 -0400
> Alexander Quest  wrote:

 x=range(1,50)
> mid=x[len(x)/2]
>
> You would have to make sure there is a way to work around decimal points in
the division. Also, I would try it in practice. (remember range(1, 50) does
not include 50.)

> ___
> 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] OT: Drag and Drop GUI IDE ideas

2011-07-28 Thread Adam Bark
Rance Hall  gmail.com> writes:
> We want the students to develop a small app in the process, It could
> be a firefox extension, mobile phone app, or any other type simple
> structure.
> 
> The catch is that the class is for non-programmers to try to get them
> introduced to the field.  We would like to use a gui ide that can
> essentially hide the code from the programmer and connect widgets with
> the gui.
> 
> We want them to be able to look at the code and analyze it.
> 
> We would prefer open source (read: free as in beer) tools.
> 
> Does anyone have any ideas of tools that can do this?
> 
> we are open to any idea, android sdk and gui, ipad sdk and some gui tool, etc.
> 
> Thanks for your time.
> 
> Rance

Hi, this isn't free but seems to tick all your other boxes
http://radicalbreeze.com/ It gives a graphical representation of your program as
well as access to the source code of your application. It creates code for many
different platforms including mobile ones and it's DRM free.
HTH,
Adam.


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


[Tutor] Sum files' size

2011-07-28 Thread Susana Iraiis Delgado Rodriguez
I want to get the size of  3 files. I already completed this step. Then I
need to sum the 3 results I got. In order to do it I have the next code:

import os
file_list = []
folders = None
for root, folders, files in os.walk('C:\\'):
file_list.extend(os.path.join(root,fi) for fi in files if
(fi.endswith.shp))
for row, filepath in enumerate(file_list, start=1):
n = os.path.splitext(filepath)
p = n[0]+'.prj'
shx = n[0]+'.shx'
s = os.path.getsize(filepath)

#Function to get size in humam readable terms:
def sizeof_fmt(num):
 for x in ['bytes','KB','MB','GB','TB']:
  if num < 1024.0:
   return "%3.1f%s" % (num, x)
  num /= 1024.0

kb = sizeof_fmt(s)
shx1 = os.path.getsize(shx)
kb2 = sizeof_fmt(shx1)

#Finally I want to sum the 3 terms:
total = kb+kb2+kb3
But the output I got is : 15.5KB108.0bytes169.0bytes

Does anyone have an idea how to fix it?
Thank you!!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sum files' size

2011-07-28 Thread Alan Gauld

Susana Iraiis Delgado Rodriguez wrote:

I want to get the size of  3 files. I already completed this step. Then I
need to sum the 3 results I got. In order to do it I have the next code:

import os
file_list = []
folders = None
for root, folders, files in os.walk('C:\\'):
file_list.extend(os.path.join(root,fi) for fi in files if
(fi.endswith.shp))
for row, filepath in enumerate(file_list, start=1):
n = os.path.splitext(filepath)
p = n[0]+'.prj'
shx = n[0]+'.shx'
s = os.path.getsize(filepath)

#Function to get size in humam readable terms:
def sizeof_fmt(num):
 for x in ['bytes','KB','MB','GB','TB']:
  if num < 1024.0:
   return "%3.1f%s" % (num, x)


This returns a string value


  num /= 1024.0

kb = sizeof_fmt(s)


So kb1 will be astring


shx1 = os.path.getsize(shx)
kb2 = sizeof_fmt(shx1)


And so will kb2


#Finally I want to sum the 3 terms:
total = kb+kb2+kb3


Where does kb3 come from?


But the output I got is : 15.5KB108.0bytes169.0bytes

Does anyone have an idea how to fix it?
Thank you!!


Looks like you are adding the strings. You need to get the
sum then call your format function on the total.

HTH,

Alan G.
___
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-28 Thread Wayne Watson

  
  
I decided to re-install.  It looks like I'm in the same boat as
before.  Edit with IDLE isn't even a choice.

I tried from the command line to run pythonw.exe, and that gave me
the typical >>> input choice. Python at least works at that
level. IDLE comes up with idle.pyw.

On 7/27/2011 3:49 PM, Prasad, Ramit wrote:

  
  
  
  

  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 

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



-- 
   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
   

Re: [Tutor] Sum files' size

2011-07-28 Thread Prasad, Ramit
>kb = sizeof_fmt(s)
>shx1 = os.path.getsize(shx)
>kb2 = sizeof_fmt(shx1)
> total = kb+kb2+kb3

Instead only retrieve the formatted output at the end. That way you will not 
have to worry about converting back from strings, nor have to worry about 
adding number with different units (e.g. 10KB + 10MB).

kb = s
kb2 = os.path.getsize(shx)
total = sizeof_fmt(kb+kb2+kb3)

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] Getting Idle to work in Win7

2011-07-28 Thread Alexander
Hi Wayne. I'm interested in the issues your facing. Could you right click on
the IDLE shortcut in your start menu and tell me the details? Specifically
under:
*General*:* type of file, description, location, attributes*, (any *advanced
* attributes?);
*Shortcut*: tab, the *Target type*, *Target location *(if any),
*Target*, *Start
in* path, *Run *choice, any *Advanced *options?
*Compatability: *anything selected here?
*Security: *Are the permissions Full control?
*Details: **name, type, path, owner*
Looking forward to resolving the issue, Alexander.

On Thu, Jul 28, 2011 at 2:38 PM, Wayne Watson
wrote:

>  I decided to re-install.  It looks like I'm in the same boat as before.
> Edit with IDLE isn't even a choice.
>
> I tried from the command line to run pythonw.exe, and that gave me the
> typical >>> input choice. Python at least works at that level. IDLE comes up
> with idle.pyw.
>
>
> On 7/27/2011 3:49 PM, Prasad, Ramit wrote:
>
>  *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  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
>
>
> --
>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: 
>
>
>
>
> ___
> Tutor maillist

Re: [Tutor] Sum files' size

2011-07-28 Thread Steven D'Aprano

Susana Iraiis Delgado Rodriguez wrote:

I want to get the size of  3 files. I already completed this step. Then I
need to sum the 3 results I got. In order to do it I have the next code:

[...]

#Finally I want to sum the 3 terms:
total = kb+kb2+kb3
But the output I got is : 15.5KB108.0bytes169.0bytes

Does anyone have an idea how to fix it?



Sum the three terms while they are still numbers, before you convert 
them into strings with units.





--
Steven

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


[Tutor] Fwd: KeyError?

2011-07-28 Thread James Reynolds
-- Forwarded message --
From: Shwinn Ricci 
Date: Thu, Jul 28, 2011 at 1:13 PM
Subject: Re: [Tutor] KeyError?
To: James Reynolds 




On Thu, Jul 28, 2011 at 12:42 PM, James Reynolds  wrote:

>
>
> On Thu, Jul 28, 2011 at 12:11 PM, Prasad, Ramit  > wrote:
>
>> *From:* tutor-bounces+ramit.prasad=jpmchase@python.org [mailto:
>> tutor-bounces+ramit.prasad=jpmchase@python.org] *On Behalf Of *Shwinn
>> Ricci
>> *Sent:* Thursday, July 28, 2011 10:51 AM
>> *To:* tutor@python.org
>> *Subject:* [Tutor] KeyError?
>>
>> ** **
>>
>> I have an excel file that I am reading cell values from and putting them
>> into a dictionary. the dictionary looks like this:
>>
>> scafPositions = {position[j]: direction[j]}
>>
>> where position[j] is exclusively floating/numerical values and
>> direction[j] is exclusively strings.
>>
>> When I try to find whether a test value val is in the array of positions,
>> and then try to look its direction up with ScafPositions[val], I get a
>> KeyError. Is this because my data isn't standalone numbers, but numbers that
>> are calculated based off other cells? Or can I not test for val?
>>
>> ==
>>
>> ** **
>>
>> Your problem is probably that you are reassigning a new dictionary to the
>> name scafPositions each time instead of updating it. You should have
>> something like the following.
>>
>> ** **
>>
>> scafPositions = {}
>>
>> ** **
>>
>> #loop structure here:
>>
>> #do stuff
>>
>> scafPositions[ position[j] ] = direction[j]
>>
>>
>>
>
> this is my code:
>

def LookUp(helix, scafPos):

 # create dictionaries (keyed by vstrand #) of
 # scaffold position with value representing orientation

book = xlrd.open_workbook('CoordinatesSpreadsheet.xls')
sheet = book.sheet_by_index(0)
cols = sheet.row_values(2,1,150)
   9
position = {}
direction = {}
scafPositions = {}
for i in range(len(cols)):
rows = sheet.col_values(i+2, 5, 500)

#create lists of position and direction, sets up dictionary
for j in range(len(rows)):
  position[j] = float(sheet.cell(j+5, i+3).value)
  direction[j] = sheet.cell(j+5, i+1).value

  scafPositions[position[j]] = direction[j]
i += 5


   #returns value for appropriate caDNAno position, which is represented as
a concatenation of the input helix and scaffold position
val = float(helix) + (float(scafPos) * 0.001)

if (scafPositions[val] == "out"):
   print "Warning: Base pointing outwards"



return scafPositions[val]


def main(argv):
return LookUp(sys.argv[1], sys.argv[2])


if __name__ == "__main__":
main(sys.argv[1:])

perhaps im on the wrong sheet? all the tutorials say "sheet0" but I'm on
openoffice and the first sheet is 'sheet1'

>
> Or it could be it's not introspecting the formula within excel and his key
> is the string "=A1*sheet2!$B$1"or it could be he's looking for a float / int
> when in reality it's a string (because it must be converted explicitly).
>
> Without a traceback and the code, it's hard to know for sure.
>
> My guess is leading towards introspection.
>
> As far as printing the contents, once you create your dict with all the
> data just use the print statement / function depending on your version of
> python
>
> print scafPositions or print(scafPositions)
>
> You could loop through it as well
>
> for key, value in scafPositions.items():
> print key, value
>
> This will give you an idea of what is in the dict.
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>

Sending this whole thing to the entire list. You should send replies to the
list as well.

going to go bit by bit here:


def LookUp(helix, scafPos):
> book = xlrd.open_workbook('CoordinatesSpreadsheet.xls')
> sheet = book.sheet_by_index(0)


ok good so far (but don't capitalize functions)

cols = sheet.row_values(2,1,150)


Here you are getting a slice of columns, from a single row. About 149
columns worth.

position = {}
> direction = {}


You don't need these dictionaries for anything useful as far as I can tell,
so drop them

for i in range(len(cols)):
> rows = sheet.col_values(i+2, 5, 500)


This doesn't make sense with the above, you are now taking a slice of rows
from a single column. I would probably rewrite this (i'll give you a
suggestion in a moment)

for j in range(len(rows)):
> position[j] = float(sheet.cell(j+5, i+3).value)
> direction[j] = sheet.cell(j+5, i+1).value
> scafPositions[position[j]] = direction[j]
> i += 5



Ok, so position isn't a dict anymore. Just make position a straight var

Re: [Tutor] Don't understand this class/constructor call syntax

2011-07-28 Thread dave
Yes that is roughly what I meant.  GNU Radio uses a lot of sub-classing--if
this is the correct term.  For example all blocks inherit hier_block2 which
has methods such as connect for connecting two blocks together.  I wondered if
the instance named self wasn't being passed as a replacement for the implicit
self parameter rather than in place of the pass_as_USRP=True parameter.

Steven D'Aprano also replied on this subject and if I understand him, then it
would require a special syntax that is not present in the GNU Radio code.

Dave





On Mon, 25 Jul 2011 08:08:54 +0100, Alan Gauld wrote
> dave wrote:
> > Is it even possible to replace the implicit self argument of the initializer
> > by passing something else?  If so, what would be the syntax.
> 
> Im not sure  this is what you mean but...
> 
> When you call a method on an object like:
> 
> class MyClass:
> def aMethod(self,spam): pass
> 
> anObject= MyClass()
> anObject.aMethod(42)
> 
> You could replace the last line with:
> 
> MyClass.aMethod(anObject, 42)
> 
> This explicitly specifies the value of self in aMethod()
> 
> So you could in theory pass any object into the method,
> although in most cases it would result in an error.
> 
> Is that what you mean?
> 
> Alan G.
> 
> ___
> 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] Sorting lists both ways at once and programmatically loading a variable.

2011-07-28 Thread Prasad, Ramit
I have 2 questions.

1. Is there a way to do a reverse and a normal sort at the same time?
I have a list of tuples (there are more than 2 elements in the tuples but I 
only want to sort by the first two). I want to sort in reverse for the first 
element (int) and in order for the second element (string).

Example: [ (1,3) (5, 2), (5, 1), (1, 1) ]. 
The output should be:[ (5,1), (5,2), (1,1), (1,3) ]
I can create a hack for this by sorting both values in order but it is a hack 
and not a "Good" solution (untested): 
>>> sorted( lst, key=lambda x: (99-x[0],x[1]) )



2. How would you programmatically get a variable when there is no class 
involved? If I was in a class I could do something like 
>>> programmatically_determined_variable = getattr( self, var_basename + 
>>> str(number) )
How would I do this from a module function or directly in the module? And is 
the solution "safe"?

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] Sorting lists both ways at once and programmatically loading a variable.

2011-07-28 Thread Dave Angel

On 07/28/2011 07:05 PM, Prasad, Ramit wrote:

I have 2 questions.

1. Is there a way to do a reverse and a normal sort at the same time?
I have a list of tuples (there are more than 2 elements in the tuples but I 
only want to sort by the first two). I want to sort in reverse for the first 
element (int) and in order for the second element (string).

Example: [ (1,3) (5, 2), (5, 1), (1, 1) ].
The output should be:[ (5,1), (5,2), (1,1), (1,3) ]
I can create a hack for this by sorting both values in order but it is a hack and not a 
"Good" solution (untested):

sorted( lst, key=lambda x: (99-x[0],x[1]) )
First point.  Nothing wrong with your solution, but you can leave out 
the 99 part.  Just use -x[0]
Another option.  Do two sorts, first on the secondary key, then on the 
primary (reversed).  Since Python's sort is stable,

it'll do the right thing.



2. How would you programmatically get a variable when there is no class 
involved? If I was in a class I could do something like

programmatically_determined_variable = getattr( self, var_basename + 
str(number) )

How would I do this from a module function or directly in the module? And is the solution 
"safe"?

Ramit

globals() is a dictionary of all the global variables, so you can do the 
same getaddr() technique.


DaveA

--

DaveA

___
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-28 Thread Alan Gauld

Wayne Watson wrote:

I tried from the command line to run pythonw.exe, and that gave me the typical 
 >>> input choice. Python at least works at that level. IDLE comes up with idle.pyw.


Don't run pythonw to catch bugs, use python (no w).

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.


HTH,

Alan G.

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


Re: [Tutor] Sorting lists both ways at once and programmatically loading a variable.

2011-07-28 Thread Alan Gauld

Prasad, Ramit wrote:

I have 2 questions.

1. Is there a way to do a reverse and a normal sort at the same time?
I have a list of tuples (there are more than 2 elements in the tuples but I 
only want to sort by the first two). I want to sort in reverse for the first 
element (int) and in order for the second element (string).

Example: [ (1,3) (5, 2), (5, 1), (1, 1) ]. 
The output should be:[ (5,1), (5,2), (1,1), (1,3) ]
I can create a hack for this by sorting both values in order but it is a hack and not a "Good" solution (untested): 

sorted( lst, key=lambda x: (99-x[0],x[1]) )


Its late and I'm going to bed so this might be ruibbish, but couldn't 
you just negate the first element? So -5 is smaller than -1 etc...


2. How would you programmatically get a variable when there is no class involved? If I was in a class I could do something like 

programmatically_determined_variable = getattr( self, var_basename + 
str(number) )

How would I do this from a module function or directly in the module? And is the solution 
"safe"?


Sorry, brain hurts trying to work out what you mean here... :-)

Good night,

Alan G.,

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


[Tutor] Mainloop conflict

2011-07-28 Thread Christopher King
Dear Tutor Dudes,
I have a socket Gui program. The only problem is that socket.recv waits
for a response, which totally screws Tkinter I think. I tried making the
timeout extremely small (it was alright if I didn't receive anything, I
was excepting that a lot) but I think that screwed socket. Anyone have words
of wisdom.

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


Re: [Tutor] Mainloop conflict

2011-07-28 Thread Dave Angel

On 07/28/2011 08:32 PM, Christopher King wrote:

Dear Tutor Dudes,
 I have a socket Gui program. The only problem is that socket.recv waits
for a response, which totally screws Tkinter I think. I tried making the
timeout extremely small (it was alright if I didn't receive anything, I
was excepting that a lot) but I think that screwed socket. Anyone have words
of wisdom.

Sincerely,
 Me


Sure:

Do the socket I/O on a separate thread.

--

DaveA

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


[Tutor] Running files from command prompt

2011-07-28 Thread Alexander Quest
I downloaded the google's python exercise files from their website (
http://code.google.com/edu/languages/google-python-class/set-up.html),
unzipped them, and placed them in C.
I then added the following to the PATH variable under system settings so
that I could type "python" in command prompt and have Windows start the
interpreter: C:\Python31;C:\Python31\Tools\Scripts

When I type in "python" in the command prompt, the interpreter opens, but
when I try to open one of the programs from the Google exercise files
(hello.py), I get the following error:
Traceback :
   File "", line 1, in 
NameError: name 'hello' is not defined

Or, if I just type in "python hello.py" first in the command prompt (as
opposed to typing in python, hitting enter, and THEN typing in hello.py, as
above), I get the following error:


python: can't open file 'hello.py': [Errno 2] No such file or directory.

So I guess my question is how do I run .py files from the command prompt now
that I seem to have gotten Windows to recognize and open the interpreter
when I type in "python"? Thanks for any help.

-Alex

P.S. Just as an aside, when I open up the command prompt, the initial
directory is C:\Users\Alexander, but my google exercises are in
C:\google-python-exercises and python itself is in C:\Python31. I don't know
if this makes a difference or not.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running files from command prompt

2011-07-28 Thread Dave Angel

On 07/28/2011 09:58 PM, Alexander Quest wrote:

I downloaded the google's python exercise files from their website (
http://code.google.com/edu/languages/google-python-class/set-up.html),
unzipped them, and placed them in C.
I then added the following to the PATH variable under system settings so
that I could type "python" in command prompt and have Windows start the
interpreter: C:\Python31;C:\Python31\Tools\Scripts

When I type in "python" in the command prompt, the interpreter opens, but
when I try to open one of the programs from the Google exercise files
(hello.py), I get the following error:
Traceback:
File "", line 1, in
NameError: name 'hello' is not defined



When you're running the python interpreter, you can't just type the name 
of your script.  You need to import it

 import hello

However, first it needs to be in the python's module search path.  
Easiest way is to make

 it your current directory.

So, from a command prompt:

cd C:\google-python-exercises

python
 starting Python version 

import hello



Or, if I just type in "python hello.py" first in the command prompt (as
opposed to typing in python, hitting enter, and THEN typing in hello.py, as
above), I get the following error:


python: can't open file 'hello.py': [Errno 2] No such file or directory.

So I guess my question is how do I run .py files from the command prompt now
that I seem to have gotten Windows to recognize and open the interpreter
when I type in "python"? Thanks for any help.

Similarly, before running python, change to the directory you want the 
script to run in.

Normally, you'd do:

cd c:\google-python-exercises
python hello.py



-Alex

P.S. Just as an aside, when I open up the command prompt, the initial
directory is C:\Users\Alexander, but my google exercises are in
C:\google-python-exercises and python itself is in C:\Python31. I don't know
if this makes a difference or not.




--

DaveA

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


Re: [Tutor] Running files from command prompt

2011-07-28 Thread Alexander Quest
Awesome- thanks for that Dave! The programs all work now, except that the
google exercise programs are all from Python 2.X and I'm running 3.1, so
some of them are giving me errors. Is there a way around this or do I have
to download a 2.X version so I can run these without a problem? Thanks
again.

-Alex

On Thu, Jul 28, 2011 at 7:11 PM, Dave Angel  wrote:

> On 07/28/2011 09:58 PM, Alexander Quest wrote:
>
>> I downloaded the google's python exercise files from their website (
>> http://code.google.com/edu/**languages/google-python-class/**set-up.html
>> ),
>> unzipped them, and placed them in C.
>> I then added the following to the PATH variable under system settings so
>> that I could type "python" in command prompt and have Windows start the
>> interpreter: C:\Python31;C:\Python31\Tools\**Scripts
>>
>> When I type in "python" in the command prompt, the interpreter opens, but
>> when I try to open one of the programs from the Google exercise files
>> (hello.py), I get the following error:
>> Traceback:
>>File "", line 1, in
>> NameError: name 'hello' is not defined
>>
>>
> When you're running the python interpreter, you can't just type the name of
> your script.  You need to import it
> import hello
>
> However, first it needs to be in the python's module search path.  Easiest
> way is to make
>  it your current directory.
>
> So, from a command prompt:
>
> cd C:\google-python-exercises
>
> python
>  starting Python version 
>
> import hello
>
>
>
>  Or, if I just type in "python hello.py" first in the command prompt (as
>> opposed to typing in python, hitting enter, and THEN typing in hello.py,
>> as
>> above), I get the following error:
>>
>>
>> python: can't open file 'hello.py': [Errno 2] No such file or directory.
>>
>> So I guess my question is how do I run .py files from the command prompt
>> now
>> that I seem to have gotten Windows to recognize and open the interpreter
>> when I type in "python"? Thanks for any help.
>>
>>  Similarly, before running python, change to the directory you want the
> script to run in.
> Normally, you'd do:
>
> cd c:\google-python-exercises
> python hello.py
>
>
>
>  -Alex
>>
>> P.S. Just as an aside, when I open up the command prompt, the initial
>> directory is C:\Users\Alexander, but my google exercises are in
>> C:\google-python-exercises and python itself is in C:\Python31. I don't
>> know
>> if this makes a difference or not.
>>
>>
>
> --
>
> DaveA
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running files from command prompt

2011-07-28 Thread Alexander Quest
To clarify, the particular file that was giving me trouble was the basic
"hello world" file. The original code on line 29 read as such: print
'Hello', name
When I ran "C:\google-python-exercises> python hello.py, it gave me an error
on that line (line 29), but when I changed that line to print ('Hello',
name), that is, including the parentheses, it printed out "hello world" as
it should. I'm assuming that this means that one of the differences between
Python 2.X and Python 3.X is that the print function necessitates
parentheses in the latter versions but not in the former. I am a bit
confused as to why this is, assuming I am correct in my assumption above,
because I was under the impression that code written for earlier python
versions will work for later python versions, as is the case here. Anyways,
I just wanted to add this info to clarify my last question regarding whether
or not I should install Python 2.X and uninstall Python 3.1 that I have now,
since I'm guessing that doing the google exercises will continue to give me
these errors with other programs (but this is, of course, still assuming
that the error cited above truly is caused by version incompatibility).

-Alex


On Thu, Jul 28, 2011 at 7:58 PM, Alexander Quest wrote:

> Awesome- thanks for that Dave! The programs all work now, except that the
> google exercise programs are all from Python 2.X and I'm running 3.1, so
> some of them are giving me errors. Is there a way around this or do I have
> to download a 2.X version so I can run these without a problem? Thanks
> again.
>
> -Alex
>
>
> On Thu, Jul 28, 2011 at 7:11 PM, Dave Angel  wrote:
>
>> On 07/28/2011 09:58 PM, Alexander Quest wrote:
>>
>>> I downloaded the google's python exercise files from their website (
>>> http://code.google.com/edu/**languages/google-python-class/**set-up.html
>>> ),
>>> unzipped them, and placed them in C.
>>> I then added the following to the PATH variable under system settings so
>>> that I could type "python" in command prompt and have Windows start the
>>> interpreter: C:\Python31;C:\Python31\Tools\**Scripts
>>>
>>> When I type in "python" in the command prompt, the interpreter opens, but
>>> when I try to open one of the programs from the Google exercise files
>>> (hello.py), I get the following error:
>>> Traceback:
>>>File "", line 1, in
>>> NameError: name 'hello' is not defined
>>>
>>>
>> When you're running the python interpreter, you can't just type the name
>> of your script.  You need to import it
>> import hello
>>
>> However, first it needs to be in the python's module search path.  Easiest
>> way is to make
>>  it your current directory.
>>
>> So, from a command prompt:
>>
>> cd C:\google-python-exercises
>>
>> python
>>  starting Python version 
>>
>> import hello
>>
>>
>>
>>  Or, if I just type in "python hello.py" first in the command prompt (as
>>> opposed to typing in python, hitting enter, and THEN typing in hello.py,
>>> as
>>> above), I get the following error:
>>>
>>>
>>> python: can't open file 'hello.py': [Errno 2] No such file or directory.
>>>
>>> So I guess my question is how do I run .py files from the command prompt
>>> now
>>> that I seem to have gotten Windows to recognize and open the interpreter
>>> when I type in "python"? Thanks for any help.
>>>
>>>  Similarly, before running python, change to the directory you want the
>> script to run in.
>> Normally, you'd do:
>>
>> cd c:\google-python-exercises
>> python hello.py
>>
>>
>>
>>  -Alex
>>>
>>> P.S. Just as an aside, when I open up the command prompt, the initial
>>> directory is C:\Users\Alexander, but my google exercises are in
>>> C:\google-python-exercises and python itself is in C:\Python31. I don't
>>> know
>>> if this makes a difference or not.
>>>
>>>
>>
>> --
>>
>> DaveA
>>
>>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] About the Mailing List

2011-07-28 Thread Jordan
How do I see what in the mailing list has already been responded too,
before it sends me the digest? For instance I wanted to respond to one
of the questions, but seeing that the time was almost two hours ago. I
am sure someone has already responded. Where could I check to see if
this is true? I assume the mailing list are posted some wheres on-line.
But I can only find the sign up page. Thanks in advance for the link.
--
Jordan
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Mainloop conflict

2011-07-28 Thread Stefan Behnel

Christopher King, 29.07.2011 02:32:

 I have a socket Gui program. The only problem is that socket.recv waits
for a response, which totally screws Tkinter I think. I tried making the
timeout extremely small (it was alright if I didn't receive anything, I
was excepting that a lot) but I think that screwed socket. Anyone have words
of wisdom.


Most of the GUI main loops (including tk, I believe) have a way to hook in 
additional file descriptors and sockets that can be listened on, so that 
you get a normal event when data becomes available in them.


Stefan

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


Re: [Tutor] Running files from command prompt

2011-07-28 Thread Steven D'Aprano

Alexander Quest wrote:

To clarify, the particular file that was giving me trouble was the basic
"hello world" file. The original code on line 29 read as such: print
'Hello', name
When I ran "C:\google-python-exercises> python hello.py, it gave me an error
on that line (line 29), but when I changed that line to print ('Hello',
name), that is, including the parentheses, it printed out "hello world" as
it should. I'm assuming that this means that one of the differences between
Python 2.X and Python 3.X is that the print function necessitates
parentheses in the latter versions but not in the former. 



Yes, that is correct.

To be a programmer (whether professional or amateur), you need to learn 
to *pay attention to the error given*. "It gave me an error" is 
meaningless. What does the error message say?


In this case, I expect it is a SyntaxError. But you need to learn to 
read the error message and understand what it is trying to tell you. 
Some errors are cryptic and don't help, but generally speaking Python is 
pretty good about giving useful error messages:



>>> a = [1, 2, 3]
>>> len a
  File "", line 1
len a
^
SyntaxError: invalid syntax


Admittedly you do need to learn that Python functions require 
parentheses, but apart from that, the error tells you what is wrong: you 
can't follow a function len with another name a without something 
between them. This is illegal syntax.





I am a bit
confused as to why this is, assuming I am correct in my assumption above,
because I was under the impression that code written for earlier python
versions will work for later python versions, as is the case here. 


Not quite. It is (mostly) true for Python 1.x and 2.x, but Python 3 has 
deliberately included some backwards incompatible changes. The biggest 
two are that strings are now Unicode rather than byte strings, and that 
print is now a function instead of a statement. So, yes, in Python 3 you 
have to call it with parentheses.


The differences are still quite minor -- think of Python 2.x and Python 
3.x being like the differences between American English and British 
English. Provided you pay attention to the error messages, and remember 
to add round brackets after print, tutorials for 2.x should still 
*mostly* work.




I just wanted to add this info to clarify my last question regarding whether
or not I should install Python 2.X and uninstall Python 3.1 that I have now,


Personally, I would consider it wiser to find a Python 3 tutorial. 
Python 3 is the future, and you will need to learn it eventually.





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


Re: [Tutor] About the Mailing List

2011-07-28 Thread Steven D'Aprano

Jordan wrote:

How do I see what in the mailing list has already been responded too,
before it sends me the digest? For instance I wanted to respond to one
of the questions, but seeing that the time was almost two hours ago. I
am sure someone has already responded. Where could I check to see if
this is true? I assume the mailing list are posted some wheres on-line.
But I can only find the sign up page. Thanks in advance for the link.


Digest mode is a pain in the backside for people wanting to reply, and 
an even bigger pain for those who read the replies to digests. Please 
consider doing yourself, and everyone else, a favour by switching to 
individual emails.


You can see the archives by going to this page here:

http://mail.python.org/mailman/listinfo/tutor

and following the links to the archives. There are *three* given: two 
external archives (Activestate and Gmane) and one held by python.org itself.





--
Steven

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


Re: [Tutor] About the Mailing List

2011-07-28 Thread Corey Richardson
Excerpts from Steven D'Aprano's message of Fri Jul 29 01:32:36 -0400 2011:
> Jordan wrote:
> > How do I see what in the mailing list has already been responded too,
> > before it sends me the digest? For instance I wanted to respond to one
> > of the questions, but seeing that the time was almost two hours ago. I
> > am sure someone has already responded. Where could I check to see if
> > this is true? I assume the mailing list are posted some wheres on-line.
> > But I can only find the sign up page. Thanks in advance for the link.
> 
> Digest mode is a pain in the backside for people wanting to reply, and 
> an even bigger pain for those who read the replies to digests. Please 
> consider doing yourself, and everyone else, a favour by switching to 
> individual emails.
> 

I'll add on to that and say find the threading feature of your user
agent -- or switch to one that has said feature. I know recent thunderbird's
do it, if that's the sort of thing you're into. Thread view makes
things bucketloads easier.
-- 
Corey Richardson
  "Those who deny freedom to others, deserve it not for themselves"
 -- Abraham Lincoln


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