[Tutor] Help Passing Variables

2012-10-18 Thread Daniel Gulko




Hi Python Tutor, I have a write a simple function named 
"SwapCaseAndCenter(a_string, width). The idea is to use the function swapcase 
and center so that when the userenters a string it centers it and swaps the 
case (e.g. upper to lower and vice versa).  The function calls for passing in 
two variables "a_string, width" but I am still confused on this concept.  In my 
code below I seem to be able to pass in the variable "a_string" and found out 
how to use the "center along with swapcase" functions. I am still unsure howto 
pass in the variable "width". In my code I have hard coded the centering but I 
am not sure if instead I use the variable width to determine the centering. Any 
suggestions, help or examples of how to do this is appreciated.  
def SwapCaseAndCenter(a_string):while True: 
a_string=raw_input("give me a word: (enter to quit): ") 
if a_string:
print a_string.center(60).swapcase()
elif not a_string:
print "you did not provide a word. goodbye"
break SwapCaseAndCenter(a_string)
Thanks, Dan   ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Objects, object references, object values and memory addresses

2012-10-18 Thread Alan Gauld

On 18/10/12 04:41, boB Stepp wrote:

 From Programming in Python 3, 2nd edition (p. 22-23):


a = ["Retention", 3, None]
b = ["Retention", 3, None]
a is b

False

b = a
a is b

True

My current understanding is as follows: On the first two lines, two
separate objects are defined, stored in two separate blocks of memory.


Two separate list objects are created. In Python it is rarely helpful to 
think about memory usage. Python is abstracted so far from the physical 
machine that the connection usually depends on the creator of the 
interpreter rather than the language.



These two objects just happen to have the same value, ["Retention", 3,
None], stored in two separate locations.


Yes, but note that its the fact that they are two separate lists that 
matters. Even if the contents were the same objects they would still be 
two lists:


>>> x = [42]
>>> y = 'spam'
>>> z = None
>>> a = [x,y,z]
>>> b = [x,y,z]   # different list, exact same content
>>> a is b
False
>>> a == b
True
>>> a = b
>>> a is b
True
>>> a == b
True
>>>

> a and b, object references (Variables are what I used to call these.

And most folks still do...


I ask: Which implementations of Python do this? In trying to make any
code I write portable across as many platforms as possible, should I
avoid using the identity operator, is (and its opposite, is not),
except when I wish to compare to None?


The point is that you don't know. And, even if you did, the very next 
release might change it so you cannot rely on it. That's the real 
message - do not assume a particular implementation technique because it 
is not guaranteed to be that way or to stay that way.


--
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] Help Passing Variables

2012-10-18 Thread Alan Gauld

On 18/10/12 08:08, Daniel Gulko wrote:


The function calls for passing in two variables "a_string, width" but I
am still confused on this concept.


You just provide the list of input parameters when you define the function:

>>> def add(x,y):
...  return x+y
...
>>> add(4,5)
9

I define add to take two parameters x and y.
I then supply two corresponding arguments, 4,5 when I call add.
I then use x and y inside my function (x+y) like ordinary variables.


am still unsure how to pass in the variable "width".


add it to your function definition as I did for add()
Then add a width value to the call to your function


centering but I am not sure if instead I use the variable width to
determine the centering.


Yes, or being pedantic, you use the parameter 'width' in your call to 
centre()



def SwapCaseAndCenter(a_string):
 while True:
 a_string=raw_input("give me a word: (enter to quit): ")
 if a_string:
 print a_string.center(60).swapcase()
 elif not a_string:
 print "you did not provide a word. goodbye"
 break


BTW putting break here means your loop only ever executes once.
Frankly I would take the loop out and prompt the user for a_string 
outside the function and pass the string in along with the width.

I'd also return the modified string so the caller can print it.

Also rather than use the elif line I'd change it to an else.
The test is implied by the fact it failed the initial if test.
Either a_string is True (it exists) or it is not True, there is no third 
option so you don't need a separate elif test.


If you really want to prompt the user multiple times do that outside the 
function:


while True:
   my_string=raw_input("give me a word: (enter to quit): ")
   if my_string:
   print SwapCaseAndCenter(my_string,60)
   else:
   print "you did not provide a word. goodbye"
   break

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] Objects, object references, object values and memory addresses

2012-10-18 Thread eryksun
On Thu, Oct 18, 2012 at 1:16 AM, Dave Angel  wrote:
>
> may decide to reuse existing objects.  This includes, ints, floats,
> strings, byte strings, tuples, etc.  In the particular case of CPython,
> small integers are cached in this way, and so are short strings with no
> whitespace.  How small, and exactly which strings is irrelevant to me,
> and hopefully to you.  The point is you cannot be sure whether equal
> immutable objects are really just a single one, or not.

In case anyone is curious about implementation trivia, CPython (2.7.3
and 3.2.3) caches integers in the closed range -5 to 256. This doesn't
apply to the long() type in 2.x.

Strings for attributes, and various other cases, are interned in a
dict. code objects intern a limited set of string constants
(alphanumeric/underscore ASCII) and also all referenced names
(co_names, co_varnames, co_freevars, and co_cellvars). The built-in
function intern() (moved to sys.intern in 3.x) manually interns a
string, e.g. for a small efficiency gain with dict lookups:

http://docs.python.org/py3k/library/sys#sys.intern
http://docs.python.org/library/functions.html#intern

To give a feel for how much string interning is used, here's the
summary after importing ctypes in a fresh interpreter and releasing
the interned strings:

3.2.3:

>>> import ctypes
>>> ctypes.pythonapi._Py_ReleaseInternedUnicodeStrings()
releasing 3996 interned strings
total size of all interned strings: 34193/0 mortal/immortal

2.7.3:

>>> import ctypes
>>> ctypes.pythonapi._Py_ReleaseInternedStrings()
releasing 2875 interned strings
total size of all interned strings: 26389/0 mortal/immortal
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help Passing Variables

2012-10-18 Thread Dave Angel
On 10/18/2012 03:08 AM, Daniel Gulko wrote:
>
>
>
> Hi Python Tutor, I have a write a simple function named 
> "SwapCaseAndCenter(a_string, width). 

So why did you define it with only one formal parameter?

> The idea is to use the function swapcase and center so that when the 
> userenters a string it centers it and swaps the case (e.g. upper to lower and 
> vice versa).  The function calls for passing in two variables "a_string, 
> width" but I am still confused on this concept.  In my code below I seem to 
> be able to pass in the variable "a_string" and found out how to use the 
> "center along with swapcase" functions. I am still unsure howto pass in the 
> variable "width". In my code I have hard coded the centering but I am not 
> sure if instead I use the variable width to determine the centering. Any 
> suggestions, help or examples of how to do this is appreciated.  
> def SwapCaseAndCenter(a_string):while True: 

As you can see, your email program thoroughly messed up this source
code.  Please send your messages in text form, as html frequently gets
trashed as it goes through various gateways.  This is a text-mailing list.

> a_string=raw_input("give me a word: (enter to quit): ") 
>  

Why do you ask the user for the input, when it was already supplied as a
parameter?  it's best practice to separate input from calculation, and
your teacher had done that in his/her specification.

>if a_string:
> print a_string.center(60).swapcase()
> elif not a_string:
> print "you did not provide a word. goodbye"
Presumably you should be returning the centered/swapped string.

No idea where the following break is supposed to happen.  But once you
eliminate the raw_input, you'll be eliminating the while True and the break.

> break SwapCaseAndCenter(a_string)
> Thanks, Dan 
-- 
DaveA

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


[Tutor] indexing a list

2012-10-18 Thread Spyros Charonis
Hello pythoners,

I have a string that I want to read in fixed-length windows.

In [68]: SEQ
Out[68]:
'MKAAVLTLAVLFLTGSQARHFWQQDEPPQSPWDRVKDLATVYVDVLKDSGRDYVSQFEGSALGKQLNLKLLDNWDSVTSTFSKLREQLGPVTQEFWDNLEKETEGLRQEMSKDLEEVKAKVQPYLDDFQKKWQEEMELYRQKVEPLRAELQEGARQKLHELQEKLSPLGEEMRDRARAHVDALRTHLAPYSDELRQRLAARLEALKENGGARLAEYHAKATEHLSTLSEKAKPALEDLRQ'

I would like a function that reads the above string, 21 characters at a
time, and checks for certain conditions, i.e. whether characters co-occur
in other lists I have made. For example:

x = 21   # WINDOW LENGTH

In [70]: SEQ[0:x]
Out[70]: 'MKAAVLTLAVLFLTGSQARHF'

In [71]: SEQ[x:2*x]
Out[71]: 'WQQDEPPQSPWDRVKDLATVY'

In [72]: SEQ[2*x:3*x]
Out[72]: 'VDVLKDSGRDYVSQFEGSALG'

How could I write a function to automate this so that it does this from
SEQ[0] throughout the entire sequence, i.e. until len(SEQ)?

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


Re: [Tutor] indexing a list

2012-10-18 Thread eryksun
On Thu, Oct 18, 2012 at 8:01 AM, Spyros Charonis  wrote:
>
> x = 21   # WINDOW LENGTH
>
> In [70]: SEQ[0:x]
> Out[70]: 'MKAAVLTLAVLFLTGSQARHF'
>
> In [71]: SEQ[x:2*x]
> Out[71]: 'WQQDEPPQSPWDRVKDLATVY'
>
> In [72]: SEQ[2*x:3*x]
> Out[72]: 'VDVLKDSGRDYVSQFEGSALG'
>
> How could I write a function to automate this so that it does this from
> SEQ[0] throughout the entire sequence, i.e. until len(SEQ)?

In your examples, the lower slice limit is 0x, 1x, 2x, and so on. The
upper limit is 1x, 2x, 3x, and so on. That should scream that you need
a counter, or range/xrange. The lower limit of the last slice should
be less than len(SEQ), such that there's at least 1 item in the last
slice. So, in terms of range, the start value is 0, and the stop value
is len(SEQ). To make things even simpler, range takes an optional step
size. This gives you the 0x, 1x, 2x, etc for the start index of each
slice. The upper bound is then i+x (corresponding to 1x, 2x, 3x, etc).
For example:

>>> seq = 'MKAAVLTLAVLFLTGSQARHFWQQDEPPQSPWDRVKDLATVYVDVLK'
>>> x = 21
>>> for i in range(0, len(seq), x):
... print(seq[i:i+x])
...
MKAAVLTLAVLFLTGSQARHF
WQQDEPPQSPWDRVKDLATVY
VDVLK

If you're using Python 2.x, use xrange instead of range, and "print"
is a statement instead of a function.

You can also use a generator expression to create a one-time iterable
object that can be used in another generator, a for loop, a
comprehension, or as the argument of a function that expects an
iterable, such as the list() constructor:

>>> chunks = (seq[i:i+x] for i in range(0, len(seq), x))
>>> list(chunks)
['MKAAVLTLAVLFLTGSQARHF', 'WQQDEPPQSPWDRVKDLATVY', 'VDVLK']
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Using the set.difference method with an unknown number of input iterables

2012-10-18 Thread Ryan Waples
I'm struggling to understand how to understand/accomplish the following:

I have an set ("a" below) and a list of sets ("not_a"), how can I pass the
elements of "not_a" to set.difference() so that it it understands I want
the difference between set "a" and all the rest

set.difference says "Changed in version 2.6: Accepts multiple input
iterables".
How can I give it multiple input iterables?

I get different error msgs depending on what I try, but they just tell me
that there is something that I'm missing here.

Thanks

#Code below
a = set([1,2,3,4])
b = set([2,3,4,5])
c = set([3,4,5,6])
d = set([4,5,6,7])

not_a = [b,c,d]
a.difference(not_a)

# I expect to return set([1]), the same as if I called:
a.difference(b,c,d)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using the set.difference method with an unknown number of input iterables

2012-10-18 Thread Emile van Sebille
On 10/18/2012 10:38 AM, Ryan Waples wrote:> I'm struggling to understand 
how to understand/accomplish the following:

>
> I have an set ("a" below) and a list of sets ("not_a"), how can I pass
> the elements of "not_a" to set.difference() so that it it understands I
> want the difference between set "a" and all the rest
>
> set.difference says "Changed in version 2.6: Accepts multiple input
> iterables".
> How can I give it multiple input iterables?
>
> I get different error msgs depending on what I try, but they just tell
> me that there is something that I'm missing here.
>
> Thanks
>
> #Code below
> a = set([1,2,3,4])
> b = set([2,3,4,5])
> c = set([3,4,5,6])
> d = set([4,5,6,7])
>
> not_a = [b,c,d]
> a.difference(not_a)

Try this as

a.difference(*not_a)

The '*' expands the list to its individual items.

HTH,

Emile


>
> # I expect to return set([1]), the same as if I called:
> a.difference(b,c,d)
>
>
>
>
> ___
> 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] Using the set.difference method with an unknown number of input iterables

2012-10-18 Thread Ryan Waples
cheers, much appreciated

-ryan

On Thu, Oct 18, 2012 at 10:52 PM, Emile van Sebille  wrote:

> On 10/18/2012 10:38 AM, Ryan Waples wrote:> I'm struggling to understand
> how to understand/accomplish the following:
>
> >
> > I have an set ("a" below) and a list of sets ("not_a"), how can I pass
> > the elements of "not_a" to set.difference() so that it it understands I
> > want the difference between set "a" and all the rest
> >
> > set.difference says "Changed in version 2.6: Accepts multiple input
> > iterables".
> > How can I give it multiple input iterables?
> >
> > I get different error msgs depending on what I try, but they just tell
> > me that there is something that I'm missing here.
> >
> > Thanks
> >
> > #Code below
> > a = set([1,2,3,4])
> > b = set([2,3,4,5])
> > c = set([3,4,5,6])
> > d = set([4,5,6,7])
> >
> > not_a = [b,c,d]
> > a.difference(not_a)
>
> Try this as
>
> a.difference(*not_a)
>
> The '*' expands the list to its individual items.
>
> HTH,
>
> Emile
>
>
>
> >
> > # I expect to return set([1]), the same as if I called:
> > a.difference(b,c,d)
> >
> >
> >
> >
> > __**_
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/**mailman/listinfo/tutor
> >
>
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Why difference between printing string & typing its object reference at the prompt?

2012-10-18 Thread Prasad, Ramit
David Hutto wrote:
> If your app has  a standard usage of phrases, you can place a file in
> that translates a tag into a particular language phrase.
> 
> 
> 
> if submit_tag_selection == 'english':
>  submit = 'Submit'
> if submit_tag_selection == 'english':
>  submit = 'Soumettre'
> 
> Of course this could be done without the if, you would just translate
> the normal selections within a file with the commonly used phrases in
> the app, and substitute it within a parse for:
> 
> x = open('translate_file_french', 'r')
> for line in x:
>  if line.split('=')[0] == 'Submit':
>print '%s'   %   (line.split('=')[1])
> 
> 'Soumettre'
> 
> *Untested, but should work
> 

Now missing any context I am going to assume the topic shifted to
how to do translations for a internationalized application/site. 
Feel free to ignore if I am wrong or OT.

I would do this, but not using line splitting. I would 
create a (YAML) config files that contain translations of
site text (i.e. "Submit"). You could do this with pickle too,
but I think YAML files are better for humans to edit.

text = ''
with open('translate_file_fr') as f:
   # parse YAML into dictionary of { text_to_replace : text_to_replace_with }
   
# 
for k,v in translation_key.iteritems():
text = text.replace(k, v)

Alternately you could create a python module and just import
the appropriate language.

translation_key = __import__('translation.' + language ) 
text = ''join([ '...', translation_key.submit_button_text, '...'])


Of course, I have no idea the downsides of this approach as I 
have not had to do something like this before. I would be
interested in whether this matches the standard approach
and the up/down-sides to it.

Ramit Prasad


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


[Tutor] good coding habits/practices

2012-10-18 Thread Andre' Walker-Loud
Hi All,

I have a general question.  I have never taken a formal programming course.  I 
have learned everything I know from office mates (earlier on) and now mostly 
Google, as I need it.  Most everything I write is only for my own consumption.  
I write scripts/programs to do science research, and have never manage to make 
the time to take a proper class, or even work through a good python tutorial.

On a matplotlib thread, someone pointed us to a PyCon talk posted on YouTube 
[for those interested - link below]

http://www.youtube.com/watch?v=pXhcPJK5cMc

This particular talk focussed on argument passing in python.  I found it very 
enjoyable and educational.

One thing I learned - I am really not aware of the coding standards out there.  
For example, I was not aware precisely of the argument passing standards 
discussed in the above talk.

However, I am aware that if I were aware of these things, my ability to do my 
research would be improved.  Especially, just being more familiar with proper 
programming.  Also, just because of personal principles, even if my code is 
only ever really consumed by me, I would like it to meet higher standards of 
"good code" than it currently does.  However, since I am still hunting for a 
permanent job, I can not take the time for a full proper course on programming 
[I still need to use the learn as I need it model].  

So finally the question:  is there a good SUCCINCT guide to things like the 
POSIX standards, and other programming standards {IEEE ... I believe), and a 
guide to good programming practices that I can peruse on the web to try and 
improve my programming skills as I work?

Also - recommended (shorter) tutorials would be nice.
With my current work schedule, things that can be worked through on the order 
of an hour or so [each lesson that is].


Thanks,

Andre

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


Re: [Tutor] good coding habits/practices

2012-10-18 Thread Alan Gauld

On 18/10/12 23:30, Andre' Walker-Loud wrote:


So finally the question:  is there a good SUCCINCT guide to things

> like the POSIX standards,

and other programming standards {IEEE ... I believe)


The problem is there are so many of these, and some of them are hundreds 
of pages long in their own right. Its impossible to do a succinct guide 
to all of them. There might be succinct guides to particular standards 
but not to all, or even most of them.



a guide to good programming practices that I can peruse

> on the web to try and improve my programming skills as I work?

I don;t know if these are on the web but they are all short books - try 
your local library for a loan...


Programming Pearls (vol1 & 2)
The practice of Programming
The pragmatic programmer

And finally, not small, but definitely one of the best all-in-one 
guides: Code Complete



 things that can be worked through on the order of an hour or so


The first 3 all fit that. Code Complete is more comprehensive and the 
chapters are longer. But its more like doing a college course on 
programming practice(note not theory!)


If you want something that will help with the art of programming design
try www.htdp.org (also in book form)

And
http://mitpress.mit.edu/sicp/full-text/book/book.html
for pure theory.
I believe MIT still use this as their standard text.

These last two are in Scheme but the principles translate to any language.

Those are my favourites once you get past the basics.

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


[Tutor] How to unpack python-dateutil-2.0.tar.gz

2012-10-18 Thread Richard D. Moores
Python 3.2.3 64 bit
MS Windows 7 Home Premium 64-bit SP1

I see python-dateutil recommended here from time to time, so I thought
I'd try it out. I downloaded python-dateutil-2.1.tar.gz from
http://pypi.python.org/pypi/python-dateutil but have forgotten how to
unpack a .tar.gz file. Please remind me.

Thanks,

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


Re: [Tutor] How to unpack python-dateutil-2.0.tar.gz

2012-10-18 Thread Mark Lawrence

On 19/10/2012 01:01, Richard D. Moores wrote:

Python 3.2.3 64 bit
MS Windows 7 Home Premium 64-bit SP1

I see python-dateutil recommended here from time to time, so I thought
I'd try it out. I downloaded python-dateutil-2.1.tar.gz from
http://pypi.python.org/pypi/python-dateutil but have forgotten how to
unpack a .tar.gz file. Please remind me.

Thanks,

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



It's easier on Windows to use pip or easy_install from the command line 
rather than mess around with unpacking .tar.gz files, especially if it 
involves having to compile anything as opposed to having a pre-built binary.


--
Cheers.

Mark Lawrence.

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


Re: [Tutor] How to unpack python-dateutil-2.0.tar.gz

2012-10-18 Thread Alan Gauld

On 19/10/12 01:01, Richard D. Moores wrote:

Python 3.2.3 64 bit
MS Windows 7 Home Premium 64-bit SP1
...
unpack a .tar.gz file. Please remind me.


Winzip or similar should cope in Windows. But a tar.gz is usually 
intended for *nix so unless its pure python it may not work in Windows. 
You might want to check for a Windows installer just

in case...

--
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] good coding habits/practices

2012-10-18 Thread Mark Lawrence

On 18/10/2012 23:30, Andre' Walker-Loud wrote:

Hi All,

I have a general question.  I have never taken a formal programming course.  I 
have learned everything I know from office mates (earlier on) and now mostly 
Google, as I need it.  Most everything I write is only for my own consumption.  
I write scripts/programs to do science research, and have never manage to make 
the time to take a proper class, or even work through a good python tutorial.

On a matplotlib thread, someone pointed us to a PyCon talk posted on YouTube 
[for those interested - link below]

http://www.youtube.com/watch?v=pXhcPJK5cMc

This particular talk focussed on argument passing in python.  I found it very 
enjoyable and educational.

One thing I learned - I am really not aware of the coding standards out there.  
For example, I was not aware precisely of the argument passing standards 
discussed in the above talk.

However, I am aware that if I were aware of these things, my ability to do my research 
would be improved.  Especially, just being more familiar with proper programming.  Also, 
just because of personal principles, even if my code is only ever really consumed by me, 
I would like it to meet higher standards of "good code" than it currently does. 
 However, since I am still hunting for a permanent job, I can not take the time for a 
full proper course on programming [I still need to use the learn as I need it model].

So finally the question:  is there a good SUCCINCT guide to things like the 
POSIX standards, and other programming standards {IEEE ... I believe), and a 
guide to good programming practices that I can peruse on the web to try and 
improve my programming skills as I work?

Also - recommended (shorter) tutorials would be nice.
With my current work schedule, things that can be worked through on the order 
of an hour or so [each lesson that is].


Thanks,

Andre

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



Given the subject I suggest you take a look at PEPs 7 and 8.

--
Cheers.

Mark Lawrence.

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


Re: [Tutor] How to unpack python-dateutil-2.0.tar.gz

2012-10-18 Thread Richard D. Moores
On Thu, Oct 18, 2012 at 5:27 PM, Alan Gauld  wrote:
> On 19/10/12 01:01, Richard D. Moores wrote:
>>
>> Python 3.2.3 64 bit
>> MS Windows 7 Home Premium 64-bit SP1
>> ...
>>
>> unpack a .tar.gz file. Please remind me.
>
>
> Winzip or similar should cope in Windows. But a tar.gz is usually intended
> for *nix so unless its pure python it may not work in Windows. You might
> want to check for a Windows installer just
> in case...

Looking at 

it's not clear that there is a Windows installer. Does someone know of
one?

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


Re: [Tutor] How to unpack python-dateutil-2.0.tar.gz

2012-10-18 Thread Richard D. Moores
On Thu, Oct 18, 2012 at 5:27 PM, Alan Gauld  wrote:
> On 19/10/12 01:01, Richard D. Moores wrote:
>>
>> Python 3.2.3 64 bit
>> MS Windows 7 Home Premium 64-bit SP1
>> ...
>>
>> unpack a .tar.gz file. Please remind me.

By trying with Peazip I got it unpacked. Here's what the PKG-INFO file
says, when opened in WordPad:

=
Metadata-Version: 1.1
Name: python-dateutil
Version: 2.1
Summary: Extensions to the standard Python datetime module
Home-page: http://labix.org/python-dateutil
Author: Tomi Pievilaeinen
Author-email: tomi.pievilai...@iki.fi
License: Simplified BSD
Description: The dateutil module provides powerful extensions to the
datetime module available in the Python standard library.

Platform: UNKNOWN
Requires: six


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


Re: [Tutor] How to unpack python-dateutil-2.0.tar.gz

2012-10-18 Thread Mark Lawrence

On 19/10/2012 01:42, Richard D. Moores wrote:

On Thu, Oct 18, 2012 at 5:27 PM, Alan Gauld  wrote:

On 19/10/12 01:01, Richard D. Moores wrote:


Python 3.2.3 64 bit
MS Windows 7 Home Premium 64-bit SP1
...

unpack a .tar.gz file. Please remind me.



Winzip or similar should cope in Windows. But a tar.gz is usually intended
for *nix so unless its pure python it may not work in Windows. You might
want to check for a Windows installer just
in case...


Looking at 

it's not clear that there is a Windows installer. Does someone know of
one?

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



Could you please take a training course on how to use a search engine. 
First hit on google for "python dateutils install windows" is 
http://stackoverflow.com/questions/879156/how-to-install-python-dateutil-on-windows


--
Cheers.

Mark Lawrence.

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


Re: [Tutor] How to unpack python-dateutil-2.0.tar.gz

2012-10-18 Thread Richard D. Moores
Running the example at
,
with Python 2.3.2 64-bit,

The importing goes OK, it seems, but:

Python 3.2.3 (default, Apr 11 2012, 07:12:16) [MSC v.1500 64 bit (AMD64)]
Type "help", "copyright", "credits" or "license" for more information.
[evaluate untitled-1.py]
Traceback (most recent call last):
  File "C:\Program Files (x86)\Wing IDE
4.1\src\debug\tserver\_sandbox.py", line 9, in 
  File "c:\Python32\Lib\site-packages\dateutil\parser.py", line 720, in parse
return DEFAULTPARSER.parse(timestr, **kwargs)
  File "c:\Python32\Lib\site-packages\dateutil\parser.py", line 310, in parse
raise ValueError("unknown string format")
builtins.ValueError: unknown string format

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


Re: [Tutor] How to unpack python-dateutil-2.0.tar.gz

2012-10-18 Thread Richard D. Moores
On Thu, Oct 18, 2012 at 6:08 PM, Mark Lawrence  wrote:

> Could you please take a training course on how to use a search engine. First
> hit on google for "python dateutils install windows" is
> http://stackoverflow.com/questions/879156/how-to-install-python-dateutil-on-windows

You're assuming I haven't searched and\or don't know how to.

Still stuck. 2 problems it seems. Your link is 3 years old. It applies
to python 2.6.

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


[Tutor] IDLE shell indentation?

2012-10-18 Thread boB Stepp
>>> if zero:
print(zero)
else:
print(phrase)


Wild Swans by Jung Chang
>>>

Is there some special way for typing in multiline blocks of code into
the shell in IDLE? The above works, but it bothers me that "else" does
not line up with "if". Also, in the IDLE shell the "p" in "print"
actually lines up under the "e" in "zero". However when I copied from
IDLE and pasted into gmail, this alignment was changed. I am guessing
it is because gmail is not using a fixed-width font. And I have yet to
figure out how to get it to use one when in plaintext mode.

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


Re: [Tutor] How to unpack python-dateutil-2.0.tar.gz

2012-10-18 Thread Steven D'Aprano

On 19/10/12 12:16, Richard D. Moores wrote:

Running the example at
,
with Python 2.3.2 64-bit,


Python TWO POINT THREE??? :-)

That's like, a million years old. I think you mean three point two.



The importing goes OK, it seems, but:

Python 3.2.3 (default, Apr 11 2012, 07:12:16) [MSC v.1500 64 bit (AMD64)]
Type "help", "copyright", "credits" or "license" for more information.
[evaluate untitled-1.py]


What does that mean?

What's "evaluate" in this context? What's inside "untitled.py"?

You're hiding the code you actually run, and expecting us to debug it unseen.
Not cool. You've been on this list long enough that you should know better.

Check your code for typos. If the error persists, check it again. If it still
persists, show us the actual relevant code. More below.



Traceback (most recent call last):
   File "C:\Program Files (x86)\Wing IDE
4.1\src\debug\tserver\_sandbox.py", line 9, in
   File "c:\Python32\Lib\site-packages\dateutil\parser.py", line 720, in parse
 return DEFAULTPARSER.parse(timestr, **kwargs)
   File "c:\Python32\Lib\site-packages\dateutil\parser.py", line 310, in parse
 raise ValueError("unknown string format")
builtins.ValueError: unknown string format


What is the value of timestr?

I note that text just before the demo code states:

[quote]
you want to get today's date out of the "date" unix system command.
[end quote]


Are you running Unix or a Unix-compatible system like Linux? Here's what `date`
outputs under Unix/Linux:

[steve@ando ~]$ date
Fri Oct 19 13:16:40 EST 2012


What does it output on your computer?



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


Re: [Tutor] How to unpack python-dateutil-2.0.tar.gz

2012-10-18 Thread eryksun
On Thu, Oct 18, 2012 at 9:55 PM, Richard D. Moores  wrote:
> On Thu, Oct 18, 2012 at 6:08 PM, Mark Lawrence  
> wrote:
>
>> Could you please take a training course on how to use a search engine. First
>> hit on google for "python dateutils install windows" is
>> http://stackoverflow.com/questions/879156/how-to-install-python-dateutil-on-windows
>
> You're assuming I haven't searched and\or don't know how to.
>
> Still stuck. 2 problems it seems. Your link is 3 years old. It applies
> to python 2.6.

For Python 3, install it with Distribute (a fork of Setuptools):
http://pypi.python.org/pypi/distribute/0.6.28

Installation script:
http://python-distribute.org/distribute_setup.py

That site seems to be down as I write this. Here's the source on
Bitbucket for the 0.6.28 release:

https://bitbucket.org/tarek/distribute/raw/fc379e63586ad3c6838e1bda216548ba8270b8f0/distribute_setup.py
short url:
http://goo.gl/R1JNJ
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] IDLE shell indentation?

2012-10-18 Thread eryksun
On Thu, Oct 18, 2012 at 10:11 PM, boB Stepp  wrote:
 if zero:
> print(zero)
> else:
> print(phrase)
>
> Is there some special way for typing in multiline blocks of code into
> the shell in IDLE? The above works, but it bothers me that "else" does
> not line up with "if". Also, in the IDLE shell the "p" in "print"
> actually lines up under the "e" in "zero". However when I copied from
> IDLE and pasted into gmail, this alignment was changed. I am guessing
> it is because gmail is not using a fixed-width font. And I have yet to
> figure out how to get it to use one when in plaintext mode.

You're right that the alignment changed because of the font rendering
of the tab character. In Firefox I use the following to get a
monospace font in Gmail:

http://userstyles.org/styles/15618/gmail-monospace-font-for-body-messages-textarea

As to your main question, I use exec:

>>> zero, phrase = '', 'spam'
>>> exec('''
if zero:
print(zero)
else:
print(phrase)
''')
spam
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to unpack python-dateutil-2.0.tar.gz

2012-10-18 Thread eryksun
On Thu, Oct 18, 2012 at 8:01 PM, Richard D. Moores  wrote:
>
> Python 3.2.3 64 bit
> MS Windows 7 Home Premium 64-bit SP1
> 
> have forgotten how to unpack a .tar.gz file. Please remind me.

shutil.unpack_archive(filename, extract_dir, 'gztar')

http://docs.python.org/release/3.2.3/library/shutil.html#shutil.unpack_archive
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] IDLE shell indentation?

2012-10-18 Thread boB Stepp
On Thu, Oct 18, 2012 at 9:46 PM, eryksun  wrote:


> You're right that the alignment changed because of the font rendering
> of the tab character. In Firefox I use the following to get a
> monospace font in Gmail:
>
> http://userstyles.org/styles/15618/gmail-monospace-font-for-body-messages-textarea

It did not occur to me to search outside of the gmail/chrome help as I
felt sure that monospace capability had to be built-in! Thanks for
pointing me elsewhere. Now all is swell.

> As to your main question, I use exec:
>
> >>> zero, phrase = '', 'spam'
> >>> exec('''
> if zero:
> print(zero)
> else:
> print(phrase)
> ''')
> spam

This does keep the alignment I desire; however, IDLE shell's
autoindent feature goes away inside the exec function. Further, my
tab, which is set to 4 spaces, becomes 8 spaces at the indent;
apparently the tab takes effect after where ">>> " would normally
occur. Of course I can just manually type the four spaces. Alas!
Perfection here is apparently unattainable! ~(:>))

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


Re: [Tutor] How to unpack python-dateutil-2.0.tar.gz

2012-10-18 Thread Richard D. Moores
On Thu, Oct 18, 2012 at 7:17 PM, Steven D'Aprano  wrote:
> On 19/10/12 12:16, Richard D. Moores wrote:
>>
>> Running the example at
>>
>> ,
>> with Python 2.3.2 64-bit,
>
>
> Python TWO POINT THREE??? :-)
>
> That's like, a million years old. I think you mean three point two.

3.2.3
>
>
>
>> The importing goes OK, it seems, but:
>>
>> Python 3.2.3 (default, Apr 11 2012, 07:12:16) [MSC v.1500 64 bit (AMD64)]
>> Type "help", "copyright", "credits" or "license" for more information.
>> [evaluate untitled-1.py]
>
>
> What does that mean?
>
> What's "evaluate" in this context? What's inside "untitled.py"? Using my IDE, 
> Wing 4.1, I opened a new file and made an exact copy-and-paste into it, and 
> accepted the default filename, "untitled.py".  "evaluate" is one of the ways 
> of running a script in Wing, "Evaluate file in Python shell".

I already said:
Running the example at


>> Traceback (most recent call last):
>>File "C:\Program Files (x86)\Wing IDE
>> 4.1\src\debug\tserver\_sandbox.py", line 9, in
>>File "c:\Python32\Lib\site-packages\dateutil\parser.py", line 720, in
>> parse
>>  return DEFAULTPARSER.parse(timestr, **kwargs)
>>File "c:\Python32\Lib\site-packages\dateutil\parser.py", line 310, in
>> parse
>>  raise ValueError("unknown string format")
>> builtins.ValueError: unknown string format
>
> I note that text just before the demo code states:
>
> [quote]
> you want to get today's date out of the "date" unix system command.
> [end quote]

I missed that. It's the first clue I could find anywhere that the
download for 3.x (x > 0) is only for a "Unix or a Unix-compatible
system like Linux".

> Are you running Unix or a Unix-compatible system like Linux?

No. See my original post.

> Here's what
> `date`
> outputs under Unix/Linux:
>
> [steve@ando ~]$ date
> Fri Oct 19 13:16:40 EST 2012
>
>
> What does it output on your computer?

I showed you everything already.

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


Re: [Tutor] IDLE shell indentation?

2012-10-18 Thread Steven D'Aprano

On 19/10/12 14:23, boB Stepp wrote:


This does keep the alignment I desire; however, IDLE shell's
autoindent feature goes away inside the exec function. Further, my
tab, which is set to 4 spaces, becomes 8 spaces at the indent;
apparently the tab takes effect after where ">>>  " would normally
occur. Of course I can just manually type the four spaces. Alas!
Perfection here is apparently unattainable! ~(:>))


If you want a decent IDE for Python, run, don't walk, run away from
IDLE.

Under Linux, the vanilla Python interactive interpreter plus a few
basic command line commands is *much* better than IDLE.

IPython is even more powerful, and still easy to use.

http://ipython.org/

Or try bpython:

http://bpython-interpreter.org/

Or try ActiveState's commercial Python install, which includes a
free IDE:

http://www.activestate.com/activepython/downloads



In my opinion, anyone using IDLE under Linux probably does it
because they like pain, and anyone using it under Windows does so
only because they don't know of the alternatives.



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


Re: [Tutor] How to unpack python-dateutil-2.0.tar.gz

2012-10-18 Thread Steven D'Aprano

On 19/10/12 14:30, Richard D. Moores wrote:


[quote]
you want to get today's date out of the "date" unix system command.
[end quote]


I missed that. It's the first clue I could find anywhere that the
download for 3.x (x>  0) is only for a "Unix or a Unix-compatible
system like Linux".


No, you have misunderstood.

The *date* command, as shown, is a unix system command. But dateutils
is not.

The relevant lines from the demo code are:

import commands
now = parse(commands.getoutput("date"))


which uses the commands module to send the command "date" to the
operating system, run it, and get the result, and only then gets
dateutil to parse the text.

You can replace those lines with:

now = parse("Fri Oct 19 13:16:40 EST 2012")


and I expect it will work.



Here's what `date` outputs under Unix/Linux:

[steve@ando ~]$ date
Fri Oct 19 13:16:40 EST 2012


What does it output on your computer?


I showed you everything already.


Have you tried running `date` at the Windows command.com (or cmd.exe,
or something, I never remember which)? What does it print?

My guess is that it probably prints something like:

"Command not found"

which clearly cannot be parsed as a date.



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


Re: [Tutor] How to unpack python-dateutil-2.0.tar.gz

2012-10-18 Thread eryksun
On Thu, Oct 18, 2012 at 11:55 PM, Steven D'Aprano  wrote:
>
> Have you tried running `date` at the Windows command.com (or cmd.exe,
> or something, I never remember which)? What does it print?
>
> My guess is that it probably prints something like:
>
> "Command not found"
>
> which clearly cannot be parsed as a date.

Windows has separate date and time commands ('date /t' and 'time /t'),
but it's simpler to use 'echo %time% %date%' in the shell.

Also, the demo script isn't for Python 3.x. It uses "print" as a
statement and the "commands" module, which is deprecated in 2.x and
removed from 3.x.

Try this instead:

import sys
import os
import subprocess
from dateutil.relativedelta import *
from dateutil.easter import *
from dateutil.rrule import *
from dateutil.parser import *
from datetime import *

if sys.platform == 'win32':
cmd = 'echo %time% %date%'
shell = True
else:
cmd = 'date'
shell = False
datestr = subprocess.check_output(cmd, shell=shell).decode()

now = parse(datestr)
today = now.date()
year = rrule(YEARLY,bymonth=8,bymonthday=13,byweekday=FR)[0].year
rdelta = relativedelta(easter(year), today)
print("Today is:", today)
print("Year with next Aug 13th on a Friday is:", year)
print("How far is the Easter of that year:", rdelta)
print("And the Easter of that year is:", today+rdelta)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] IDLE shell indentation?

2012-10-18 Thread eryksun
On Thu, Oct 18, 2012 at 11:23 PM, boB Stepp  wrote:
>
> This does keep the alignment I desire; however, IDLE shell's
> autoindent feature goes away inside the exec function. Further, my
> tab, which is set to 4 spaces, becomes 8 spaces at the indent;
> apparently the tab takes effect after where ">>> " would normally
> occur. Of course I can just manually type the four spaces. Alas!
> Perfection here is apparently unattainable! ~(:>))

The shell in IDLE doesn't replace tabs with spaces for me. I hadn't
considered the loss of auto-indenting. I don't use IDLE, and only use
exec() like I showed when pasting an arbitrary selection of code into
a terminal.

IPython's Qt console does auto-indenting and replaces tabs with 4 spaces:

In [1]: zero, phrase = '', 'spam'

In [2]: if zero:
   ...: print(zero)
   ...: else:
   ...: print(phrase)
   ...:
spam

http://ipython.org/ipython-doc/dev/interactive/qtconsole.html

Also, IEP is a nice little IDE that I used to use. I think it's a vast
improvement over IDLE. It works simultaneously with different
interpreters (2.x, 3.x, pypy) and GUI toolkits.

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


Re: [Tutor] How to unpack python-dateutil-2.0.tar.gz

2012-10-18 Thread Richard D. Moores
On Thu, Oct 18, 2012 at 9:41 PM, eryksun  wrote:
> On Thu, Oct 18, 2012 at 11:55 PM, Steven D'Aprano  wrote:
>>
>> Have you tried running `date` at the Windows command.com (or cmd.exe,
>> or something, I never remember which)? What does it print?
>>
>> My guess is that it probably prints something like:
>>
>> "Command not found"
>>
>> which clearly cannot be parsed as a date.
>
> Windows has separate date and time commands ('date /t' and 'time /t'),
> but it's simpler to use 'echo %time% %date%' in the shell.
>
> Also, the demo script isn't for Python 3.x. It uses "print" as a
> statement and the "commands" module, which is deprecated in 2.x and
> removed from 3.x.
>
> Try this instead:
>
> import sys
> import os
> import subprocess
> from dateutil.relativedelta import *
> from dateutil.easter import *
> from dateutil.rrule import *
> from dateutil.parser import *
> from datetime import *
>
> if sys.platform == 'win32':
> cmd = 'echo %time% %date%'
> shell = True
> else:
> cmd = 'date'
> shell = False
> datestr = subprocess.check_output(cmd, shell=shell).decode()
>
> now = parse(datestr)
> today = now.date()
> year = rrule(YEARLY,bymonth=8,bymonthday=13,byweekday=FR)[0].year
> rdelta = relativedelta(easter(year), today)
> print("Today is:", today)
> print("Year with next Aug 13th on a Friday is:", year)
> print("How far is the Easter of that year:", rdelta)
> print("And the Easter of that year is:", today+rdelta)

Yes! Thanks!

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