Re: [Tutor] trying to split or rpartition the contents of a list

2013-05-23 Thread Stuart Tozer
Hello Amit- your solution works very well. Thanks very much!

Best regards,
Stu


On Wed, May 22, 2013 at 11:39 AM, Stuart Tozer  wrote:

> Thanks very much guys- I'll get back to this when I have a spare moment
> and let you know how I get on.
>
> Cheers,
> Stu
>
>
>
> On Wed, May 22, 2013 at 11:06 AM, Albert-Jan Roskam wrote:
>
>> >
>>
>> >forobjectinobjects:sorted(set(object.split('_',1)[0]))cmds.menuItem(label
>> =object,parent ="objectMenu")
>>
>>
>> "sorted" returns the sorted list but you don't assign anything to it. You
>> can either assign it to a variable, or use the .sort method instead. Also,
>> you don't need to specify the maxsplit argument (1) in .split. Also, you
>> used 'object' as a loop index but this is a reserved word. Why not use the
>> more descriptive "for filename in filenames"?
>>
>
>
>
> --
> http://stutozer.elementfx.com/
>
>
>


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


Re: [Tutor] trying to split or rpartition the contents of a list

2013-05-23 Thread Amit Saha
Hi Stuart,

On Thu, May 23, 2013 at 10:57 PM, Stuart Tozer  wrote:
> Hello Amit- your solution works very well. Thanks very much!

Good to know that! Hope it was clear.

All the best.
-Amit

>
> Best regards,
> Stu
>
>
> On Wed, May 22, 2013 at 11:39 AM, Stuart Tozer  wrote:
>>
>> Thanks very much guys- I'll get back to this when I have a spare moment
>> and let you know how I get on.
>>
>> Cheers,
>> Stu
>>
>>
>>
>> On Wed, May 22, 2013 at 11:06 AM, Albert-Jan Roskam 
>> wrote:
>>>
>>> >
>>>
>>>
>>> > >forobjectinobjects:sorted(set(object.split('_',1)[0]))cmds.menuItem(label
>>> > =object,parent ="objectMenu")
>>>
>>>
>>> "sorted" returns the sorted list but you don't assign anything to it. You
>>> can either assign it to a variable, or use the .sort method instead. Also,
>>> you don't need to specify the maxsplit argument (1) in .split. Also, you
>>> used 'object' as a loop index but this is a reserved word. Why not use the
>>> more descriptive "for filename in filenames"?
>>
>>
>>
>>
>> --
>> http://stutozer.elementfx.com/
>>
>>
>
>
>
> --
> http://stutozer.elementfx.com/
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



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


Re: [Tutor] keyboard interrupt

2013-05-23 Thread Jerry Hill
On Wed, May 22, 2013 at 9:25 PM, Dave Angel  wrote:

> On 05/22/2013 04:11 PM, Jerry Hill wrote:
>
>> The KeyboardInterrupt ​exception is raised when someone presses Ctrl-C.
>>  If
>> you catch it, and ignore it (which is what your code above is doing), then
>> pressing Ctrl-C doesn't do anything.  If you just take out the try/except,
>> then you can hit Ctrl-C and interrupt your program as normal.
>>
>>
> What do you mean "doesn't do anything" ?  It certainly terminates the
> loop, which was the intent.  Provided of course that something else isn't
> trapping the Ctrl-C first.
>

​You're quite right.  I mis-read the original code as having the try/except
inside the loop.  ​The way Jim wrote it was correct.

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


Re: [Tutor] try..except - what about that ton of **Error statements?

2013-05-23 Thread boB Stepp
On Wed, May 22, 2013 at 8:47 PM, Steven D'Aprano  wrote:
> On 23/05/13 02:09, boB Stepp wrote:
>
>> I would like to ask some general questions here. Problems can arise
>> from bugs in the operating system, bugs in the programming language(s)
>> being used, bugs in packages/modules being used, bugs in any third
>> party packages being used, etc. Also, whenever any one of these things
>> is updated/upgraded, it can introduce new issues. What strategies can
>> one use to deal with these possibilities that seem entirely out of the
>> programmer's control?
>
>
>
> They're not really out of your control though. You can always write code
> to work around them.
>

I have found myself having to do this when I write scripts for my
radiation planning software at work. There are frequently rather
quirky behaviors in this software that I have to work around. And
there seems to be a different set of quirky behaviors every time the
software is upgraded.

[...]

>
> Sometimes it is sufficient to just avoid triggering the bug. Sometimes you
> might need use a different tool. For instance, in Python, print is not
> "thread safe" -- if you have two different threads trying to print at the
> same time, their output may interleave.
>

I did not know this.

[...]

>
> So working around bugs is, in general, possible, even if sometimes it is
> hard.
>
> A general technique when programming is to always have a good, solid test
> suite. This will detect any change in behaviour, whether due to your own
> programming errors, on bugs in the language or operating system. What you do
> is as you develop your own code, in parallel you also develop a second
> program that tests as much of your code as you can.
>

I guess this is the test driven development I have heard about.

[...]

>
> (Or you can use a test frame work like unittest or doctest or both.) Now,
> whenever you change something, say you upgrade to a new version of the
> language, or change your code, you run the test file and see what tests
> start failing. Each failed test indicates a bug that needs to be fixed,
> although it doesn't tell you what introduced the bug.
>
So this method of development is a good friend that keeps on giving! ~(:>))

More general questions: How do you keep up with the ongoing changes in
your development languages? One thing I have found frustrating in
learning Python at my rather slow pace (Due to limited time.) is that
the versions keep changing! Worse, at least in the case of Windows, is
there is a constant deluge of security updates, etc. Are you
constantly reading release notes to keep up? Is there a more efficient
way? It seems that if one has written a significant program for
Windows one would have to run one's automated test suite every time
there are updates. I wonder how often problems arise that have to be
dealt with? At least with Solaris at work, they only update the OS
when they update the hardware.

This has been very informative! I have so much to learn...

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


[Tutor] installing old versions of python on Mac OS X

2013-05-23 Thread Robert R
Hi,

I have Mac OS X 10.7.5 and would like to install < = python 2.3 on it.

I need it as one of the s/w I would like to try is based on an older version 
and does not seem to work with the new ones.
I am not sure if the s/w is wrong (doesn't seem like it) or is it really the 
python version that is messing it up.

I tried 2.4 (using mac ports) but thats not it so I want to go further back but 
I cannot do it with fink or mac ports.

Any other suggestions ? I tried to install using a tar file but that gave 
errors.
I am sorry for the dumb question. Thank you for the help
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Presenting text in different ways by using quotes!

2013-05-23 Thread Andrew Triplett
I am asked to present text in different ways by using quotes in strings. for 
example:

print("Program "Game Over" 2.0")

print("same", "message", "as before")

print("just", 

    "a bit", 

    "bigger")

print("Here", end=" ")
print("it is...")

print(

  """





    """
)

I can't however seem to input the text GAME OVER in giant text as it says in 
the book. Any help for this would be appreciated.

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


Re: [Tutor] Presenting text in different ways by using quotes!

2013-05-23 Thread Dave Angel

On 05/23/2013 01:31 PM, Andrew Triplett wrote:

I am asked to present text in different ways by using quotes in strings. for 
example:

print("Program "Game Over" 2.0")


syntax error.  If you need quotes inside quotes, you probably want to 
use single-quotes for one type.  For example,


print('Program "Game Over" 2.0')



print("same", "message", "as before")

print("just",

 "a bit",

 "bigger")

print("Here", end=" ")
print("it is...")

print(

   """





 """
)

I can't however seem to input


I suppose you mean "output"


the text GAME OVER in giant text as it says in the book. Any help for this 
would be appreciated.



How does the book suggest you get text to be "giant" ?  If you write a 
console app, you're out of luck.  And I doubt if you're learning to 
program a GUI quite yet.



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


[Tutor] Fwd: Available characters

2013-05-23 Thread Citizen Kant
Thanks!

There are only 127 ASCII characters, so getting a list of them is trivial:

ascii = map(chr, range(128))  # Python 2
ascii = list(map(chr, range(128)))  # Python 3


or if you prefer a string:

ascii = ''.join(map(chr, range(128)))


If you don't like map(), you can use a list comprehension:

[chr(i) for i in range(128)]

The string module already defines some useful subsets of them:

py> import string
py> string.printable
'**0123456789abcdefghijklmnopqrst**uvwxyzABCDEFGHIJKLMNOPQRSTUVWX**
YZ!"#$%&\'()*+,-./:;<=>?@[\\]^**_`{|}~ \t\n\r\x0b\x0c'


There are 1114111 (hexadecimal 0x10) possible Unicode code-points, but
most of them are currently unassigned. Of those that are assigned, many of
them are reserved as non-characters or for special purposes, and even those
which are assigned, most fonts do not display anything even close to the
full range of Unicode characters.

If you spend some time on the Unicode web site, you will find lists of
characters which are defined:

www.unicode.org

but beware, it is relatively heavy going. Wikipedia has a page showing all
currently assigned characters, but font support is still lousy and many of
them display as boxes:

http://en.wikipedia.org/wiki/**List_of_Unicode_characters

You can generate the entire list yourself, using the same technique as for
ASCII above:


# Python 2:
unicode = ''.join(map(unichr, xrange(1114112)))

# Python3:
unicode = ''.join(map(chr, range(1114112)))


although it will take a few seconds to generate the entire range. You can
then get the name for each one using something like this:

import unicodedata
for c in unicode:
try:
print(c, unicodedata.name(c))
except ValueError:
# unassigned, or a reserved non-character
pass


but remember that there are currently almost 100,000 defined characters in
Unicode, and your terminal will probably not be able to print most of them.
Expect to see a lot of boxes
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Presenting text in different ways by using quotes!

2013-05-23 Thread boB Stepp
On Thu, May 23, 2013 at 12:31 PM, Andrew Triplett
 wrote:
> I am asked to present text in different ways by using quotes in strings. for
> example:
>

[...]

> I can't however seem to input the text GAME OVER in giant text as it says in
> the book. Any help for this would be appreciated.
>
I'm taking a wild guess here, but is the books author(s) wanting you
to use forward slashes, back slashes, underscores and spaces as the
components of your print functions to form a mosaic which looks like
an enlarged GAME OVER ? If you line up everything correctly this can
be done. You just have to play around with the spacing, both
horizontally and vertically.

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


[Tutor] Difference between types

2013-05-23 Thread Citizen Kant
I guess I'm understanding that, in Python, if something belongs to a type,
must also be a value.

I guess I'm understanding that the reason why 9 is considered a value, is
since it's a normal form*,* an element of the system that cannot be
rewritten and reduced any further.

I also guess I'm understanding that the same goes somehow for the letter A
for example, since it cannot be rewritten or reduced any further, so it's a
value too.

type('A')


The question is, in order to understand: does this apostrophes thing has a
more profound reason to be attached to the letters or it's just a
conventional way to set a difference between letters and numbers? Do I must
observe this apostrophes thing like the symbol of the type itself inside
which one can put any character, setting it as type str?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Difference between types

2013-05-23 Thread Matthew Ngaha
wait for someone more knowledgeable to answer, but from what i know,
Yes it does have a profound meaning.  Strings consist of character
sets. Something that was here way before Python

Like i said my experience is limited so i too would like to hear some reponses
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Difference between types

2013-05-23 Thread boB Stepp
On Thu, May 23, 2013 at 2:57 PM, Citizen Kant  wrote:
> I guess I'm understanding that, in Python, if something belongs to a type,
> must also be a value.
>
> I guess I'm understanding that the reason why 9 is considered a value, is
> since it's a normal form, an element of the system that cannot be rewritten
> and reduced any further.
>
> I also guess I'm understanding that the same goes somehow for the letter A
> for example, since it cannot be rewritten or reduced any further, so it's a
> value too.
>
> type('A')
> 
>
> The question is, in order to understand: does this apostrophes thing has a
> more profound reason to be attached to the letters or it's just a
> conventional way to set a difference between letters and numbers? Do I must
> observe this apostrophes thing like the symbol of the type itself inside
> which one can put any character, setting it as type str?
>
I asked a similar question a while back. Here is a link to my original
question in the ActiveState Tutor archives:

http://code.activestate.com/lists/python-tutor/91223/

If you look at the bottom it shows all of the links to answers offered.

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


Re: [Tutor] keyboard interrupt

2013-05-23 Thread Jim Mooney
> Apparently Wing isn't as savvy as IDLE when it comes to communicating
> with the subprocess. I've only searched for about a minute, but
> apparently the way this works in Wing is to "Restart Shell":
>
> http://stackoverflow.com/a/10360503/205580
> http://www.wingware.com/doc/debug/interactive-python-shell
>
> This kills the suprocess and starts a new interpreter. Crude, but it
> should get the job done.

Thanks. I'll put stackoverflow on my bookmarks. There is still a
difference, though. The program (as corrected below) prints out the
last sound heard as a hearing test, if you press Ctrl-C in Idle or the
Windows Command Console, but prints nothing if you use Option >
Restart Shell in Wing 101. Here's the corrected program if anyone
wants to test their hearing ;')

Oh, as a tip for winusers who have avoided the Win command console, I
also did because I thought you had to type in one line at a time. I
just found I can right-click > paste an entire Py program in (after
you start Python). The prog then starts after you hit Enter twice.
This is Win 7.

import winsound

try:
for freq in range(100,32000,100):
winsound.Beep(freq, 1000)
except KeyboardInterrupt:
print 'last frequency heard was', freq - 100
exit(0)

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


Re: [Tutor] keyboard interrupt

2013-05-23 Thread Steven D'Aprano

On 24/05/13 06:37, Jim Mooney wrote:

Apparently Wing isn't as savvy as IDLE when it comes to communicating
with the subprocess. I've only searched for about a minute, but
apparently the way this works in Wing is to "Restart Shell":

http://stackoverflow.com/a/10360503/205580
http://www.wingware.com/doc/debug/interactive-python-shell

This kills the suprocess and starts a new interpreter. Crude, but it
should get the job done.


Thanks. I'll put stackoverflow on my bookmarks.


Beware though, while there are often some very good answers on Stackoverflow, 
there are also very many people who are nowhere near as knowledgeable as they 
think, giving terrible answers, and still having large scores. (One particular 
person comes to mind, I forget his name but he has a *very* high score which 
means lots of people are voting for his answers, and yet every time without 
exception I've seen him reply to someone he has been rude, missed the entire 
point of their question, or given them bad advice. Or all three at once.)

Personally, I think Stackoverflow is a great resource for experienced Python 
programmers who can separate the wheat from the chaff, but only a moderately 
okay resource for beginners :-)




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


Re: [Tutor] Difference between types

2013-05-23 Thread Dave Angel

On 05/23/2013 03:57 PM, Citizen Kant wrote:

It's quite hard to believe that you're not just trolling.  Little that 
you say below makes any sense with regards to Python.




I guess I'm understanding that, in Python, if something belongs to a type,
must also be a value.



Nothing belongs to a type.  Objects created during the running of a 
program do have a definite type, and a definite value.  Some are 
immutable, meaning they cannot change.  Others are mutable. Examples are 
int and list, respectively.



I guess I'm understanding that the reason why 9 is considered a value, is
since it's a normal form*,* an element of the system that cannot be
rewritten and reduced any further.


9 is a numeric literal in your source code that describes the integer 
nine.  Since it starts with a digit, and does not have quotes around it, 
it will be represented in the virtual machine as an integer object.




I also guess I'm understanding that the same goes somehow for the letter A
for example, since it cannot be rewritten or reduced any further, so it's a
value too.



The letter A in your source code might be almost anything.  If it stands 
by itself, or is surrounded just by letters and digits, then it's a 
name, or identifier, presumably defined in some namespace.


That same A in the source code could be part of a string literal, if 
it's between quote marks.  The quote marks are not part of the string, 
they're merely part of the literal representation.  The language parser 
has to have some way of deciding whether you meant it as a name, or as a 
string.  The quotes define that.



type('A')


The question is, in order to understand: does this apostrophes thing has a
more profound reason to be attached to the letters or it's just a
conventional way to set a difference between letters and numbers?


Letters and numbers can both be used inside a string literal.  What 
makes it a string literal is the presence of quote marks.



Do I must
observe this apostrophes thing like the symbol of the type itself inside
which one can put any character, setting it as type str?



No clue what that's supposed to mean.

When the compiler processes your source file, it tokenizes it into some 
byte code.  When that byte code executes, objects are created, 
identifiers are bound and unbound to those objects, expressions are 
evaluated, functions are called, and possibly external devices are 
spoken to.


A string object has no quote marks around it (unless you go out of your 
way to add them to the string explicitly), and an int object has no 
definite format that is defined in the language.  They both have values, 
and sometimes its convenient to describe those values in the terms of 
source code.   But an int object for example is unlikely to be in base ten.


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


[Tutor] making a random list, then naming it

2013-05-23 Thread Jim Mooney
I keep needing random lists of integers for trying things, so I wrote
a small prog I'll import as randlist. The user enters the length and
max val, but then I want the actual data name of the random list
created, to be   list_(length entered)_(max value entered)  as an easy
mnemonic.

I got as far as making the list, but my brain is fozzled on changing
the numbers entered into part of a data name. Feels like I have to go
outside the program to do it:

import random
random.seed

listparameters = raw_input('\nEnter two numbers, space separated, for
the length and largest value of a zero-starting random list, which can
be used as variable name:  randlist.list_len_max , where len is the
list length you entered, and max is the largest value\n')

listargs = listparameters.split()
rlist = []
length = int(listargs[0])
maxval = int(listargs[1])
for r in range(0,length):
rlist.append(random.randint(0,maxval))

listlenmax = 'list' + '_' + str(length) + '_' + str(maxval)   # just
the name of a string, not the data name I want

#just printing the below as a test - they'll be removed when the import works

print
print rlist
print
print listlenmax

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


Re: [Tutor] Difference between types

2013-05-23 Thread Steven D'Aprano

On 24/05/13 05:57, Citizen Kant wrote:

I guess I'm understanding that, in Python, if something belongs to a type,
must also be a value.


Everything in Python is a value, and everything belongs to a type. Including other types. Yes, 
types are values too, and types have types of their own. There is no infinite regress, because 
ultimately everything ends at the "magic" type called "type", which is its own 
type:


py> type(42)  # 42 is an instance of int

py> type(int)  # int is an instance of type

py> type(type)  # type is an instance of itself!




I guess I'm understanding that the reason why 9 is considered a value, is
since it's a normal form*,* an element of the system that cannot be
rewritten and reduced any further.


Are you referring to this definition?

http://en.wikipedia.org/wiki/Value_%28computer_science%29

As far as it goes, that's not an unreasonable rule of thumb, but it isn't 
bullet-proof. What, for example, do you make of this:

0x09

Is that a value? I say yes, because that is a literal expression for the 
natural number 9. It merely happens to use hexadecimal notation instead of 
decimal notation. Another language might define keywords one, two, three ... 
nine, ten which are also literal expressions for the same natural number, only 
using English words instead of numerals.

But let's not worry about hypothetical languages with such keywords. Even in 
Python, each of these represent the exact same value:

9 0x09 0o10 0b1001

They are the same value, using different notation.



I also guess I'm understanding that the same goes somehow for the letter A
for example, since it cannot be rewritten or reduced any further, so it's a
value too.


Likewise for every object. Compound objects are also values:

iter([12, 3, None, "hello world!", 4.5, ('a', 'b', 3), {}])


but the fact that it is a value is not really captured by the definition given 
above. The definition is true so far as it goes, but it doesn't go far enough.



type('A')


The question is, in order to understand: does this apostrophes thing has a
more profound reason to be attached to the letters or it's just a
conventional way to set a difference between letters and numbers?


The later. It is a long standing tradition in computer programming that so-called 
"strings" (ordered sequences of letters, digits and other characters) are 
defined using a notation that includes quotation marks as delimiters. In contrast, 
numbers are written in straight numeric form, usually in base-10 but sometimes in other 
bases.

This is not a hard rule, but it is a strong tradition, and any language which did 
differently would be considered strange. Some languages give '' and "" 
different meanings, but Python does not.



 Do I must
observe this apostrophes thing like the symbol of the type itself inside
which one can put any character, setting it as type str?


I'm afraid that I don't understand the question.


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


Re: [Tutor] making a random list, then naming it

2013-05-23 Thread Dave Angel

On 05/23/2013 10:39 PM, Jim Mooney wrote:

I keep needing random lists of integers for trying things, so I wrote
a small prog I'll import as randlist. The user enters the length and
max val, but then I want the actual data name of the random list
created, to be   list_(length entered)_(max value entered)  as an easy
mnemonic.




> print
> print rlist
> print
> print listlenmax
>

By "name of the list" do you mean like the names rlist and listlenmax 
above?  In other words, you want to define an identifier at run time, 
and bind it to the list object that you have calculated.


And just how would you know you succeeded, unless you already had code 
that happened to use that same identifier?


The short answer is that Python is not designed to be able to do such a 
thing.  You're advised instead to make a dictionary, where the key is 
the name you generate


lists = {}


for .
key = 'list' + '_' + str(length) + '_' + str(maxval)
lists[key] = buildlist(length, maxval)
--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor