Re: [Tutor] Python Book recomandation!

2010-07-16 Thread Ethan Wei
For BOOK recommend:my favor. :)

For promote you skill:  Find a short python source code(ex.from open source
project) and read it. you can learn more useful programing methods.


2010/7/16 Alan Gauld 

>
> "Daniel"  wrote
>
>  Python website, but I have a question regarding it. With what book I
>> should
>> start learning Python? Or should I take them in the order they are
>> presented
>> there on the website?I have no previous programming experience, thanks.
>>
>
> Don't try to read them all!
>
> They all present much the same information just in different styles.
> Some major on getting you writing code quickly, some present a more
> theoretical
> basis first. Some use a common theme or project others use lots of
> different a
> shorter projects. There is no right or best approach, pick the one that
> sems to
> work best for you.
>
> Much will depend on what you want to do with your new skills and what your
> previous experience is. If you can already program in another language the
> official tutor is probably the best starting place, but if you don't
> already
> programme much of it will be meaningless.
>
> The one that is best for you can only be decided by you!
>
> HTH,
>
> --
> Alan Gauld
> 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 maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I don't understand this code

2010-07-16 Thread ZUXOXUS
Hey,

thanks for your help!

I couldn't understand because I didn't see that further down in the code, as
Serdar Tumgoren said, the function was called:

secretWord = getRandomWord(words)

without that line I couldn't get it.

Thank you very much, everybody, great explanations.

Alan, I have been checking your tutorial too, great job.



2010/7/13 ZUXOXUS 

> Hi,
>
> I am a true beginner in programming, and im learning with
> inventwithpython.com.
>
> There's something I dont understand, and i would really appreciate any
> help.
>
> In chapter 9, the one about the Hangman game, I don't get the block of code
> in line 61
>
> 59.  words = 'ant baboon badger bat bear'
> 60.
>
>1. def getRandomWord(wordList):
>2. # This function returns a random string from the passed list of
>strings.
>3. wordIndex = random.randint(0, len(wordList) - 1)
>4. return wordList[wordIndex]
>
>
> The thing is, the "passed list of strings" is called "words", not
> "wordList", so I see it shouldn't work.
>
> On the other hand, the variable "wordList" is defined nowhere!
>
> The code is ok, because the program runs ok. So there is somethings that i
> dont get.
>
> Thank you very much in advance.
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Removing GB pound symbols from Beautiful soup output

2010-07-16 Thread Andy

Dear Nice people

I've been using beautiful soup to filter the BBC's rss feed. However, 
recently the bbc have changed the feed and it is causing me problems 
with the pound(money) symbol. The initial error was "UnicodeEncodeError: 
'ascii' codec can't encode character u'\xa3'" which means that the 
default encoding can't process this (unicode) character. I was having 
simular problems with HTML characters appearing but I used a simple 
regex system to remove/substitute them to something suitable.
I tried applying the same approach and make a generic regex patten 
(re.compile(u"""\u\[A-Fa-f0-9\]\{4\}""") but this fails because it 
doesn't follow the standard patten for ascii. I'm not sure that I 100% 
understand the unicode system but is there a simple way to 
remove/subsitute these non ascii strings?


Thanks for any help!

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


Re: [Tutor] Removing GB pound symbols from Beautiful soup output

2010-07-16 Thread Ethan Wei
1st. what's the BBC's rss page coding? UTF-8 or something.
2nd. confirm you file coding and document coding equate rss page coding.
3rd. add fromEncoding to you BeautifulSoup instance。

>  ex. soup = BeautifulSoup(html,fromEncoding="utf-8")
>


2010/7/16 Andy 

> Dear Nice people
>
> I've been using beautiful soup to filter the BBC's rss feed. However,
> recently the bbc have changed the feed and it is causing me problems with
> the pound(money) symbol. The initial error was "UnicodeEncodeError: 'ascii'
> codec can't encode character u'\xa3'" which means that the default encoding
> can't process this (unicode) character. I was having simular problems with
> HTML characters appearing but I used a simple regex system to
> remove/substitute them to something suitable.
> I tried applying the same approach and make a generic regex patten
> (re.compile(u"""\u\[A-Fa-f0-9\]\{4\}""") but this fails because it doesn't
> follow the standard patten for ascii. I'm not sure that I 100% understand
> the unicode system but is there a simple way to remove/subsitute these non
> ascii strings?
>
> Thanks for any help!
>
> Andy
> ___
> 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] append, list and variables

2010-07-16 Thread Mary Morris
Thanks-that helps a lot.
The only question I have about your pseudocode is what the 'initialize
result container' does.  I'm pretty new to python and scripting in general
so I'm still trying to figure everything out.

On Thu, Jul 15, 2010 at 12:58 PM, Emile van Sebille  wrote:

> On 7/15/2010 11:32 AM Mary Morris said...
>
>  Hi,
>> I'm working on a program that parses through all of our source code at my
>> office and i need to get my code to print a list of the decorators.  I
>> used
>> a find(@) to locate all the decorators, but I need to assign them to a
>> variable somehow to get it to print a list. How do I do this? How do I
>> assign a variable to all the indexed strings after the @ symbol?
>>
>>
> So, decorator lines start with an '@'.  Source files end in '.py'.
>
> Pseudo code could be:
> 
> initialize result container
>
> with each sourcefilename in globbed list:
>  for eachline in opened(sourcefilename):
>if line.startswith('@'):
>  append [sourcefilename, line] to result
>
> # print it
>
> for eachline in result:
>  print eachline
> 
>
> Hope this gets you going,
>
> Emile
>
>
>
>
> ___
> 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] append, list and variables

2010-07-16 Thread Emile van Sebille

On 7/16/2010 8:37 AM Mary Morris said...

Thanks-that helps a lot.
The only question I have about your pseudocode is what the 'initialize
result container' does.  I'm pretty new to python and scripting in general
so I'm still trying to figure everything out.


It creates an empty data storage container for use within the processing 
loop -- if it wasn't defined before use, you'd get an error the first 
time you tried to append to it.  There's some good info in the tutorial 
-- see http://docs.python.org/tutorial/datastructures.html for details.


Emile





On Thu, Jul 15, 2010 at 12:58 PM, Emile van Sebille  wrote:


On 7/15/2010 11:32 AM Mary Morris said...

  Hi,

I'm working on a program that parses through all of our source code at my
office and i need to get my code to print a list of the decorators.  I
used
a find(@) to locate all the decorators, but I need to assign them to a
variable somehow to get it to print a list. How do I do this? How do I
assign a variable to all the indexed strings after the @ symbol?



So, decorator lines start with an '@'.  Source files end in '.py'.

Pseudo code could be:

initialize result container

with each sourcefilename in globbed list:
  for eachline in opened(sourcefilename):
if line.startswith('@'):
  append [sourcefilename, line] to result

# print it

for eachline in result:
  print eachline


Hope this gets you going,

Emile




___
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] append, list and variables

2010-07-16 Thread pk



Dnia 16-07-2010 o 19:54:01 Emile van Sebille  napisał(a):> On 7/16/2010 8:37 AM Mary Morris said...>> Thanks-that helps a lot.>> The only question I have about your pseudocode is what the 'initialize>> result container' does.  I'm pretty new to python and scripting in  >> general>> so I'm still trying to figure everything out.>> It creates an empty data storage container for use within the processing  > loop -- if it wasn't defined before use, you'd get an error the first  > time you tried to append to it.  There's some good info in the tutorial  > -- see http://docs.python.org/tutorial/datastructures.html for details.>> Emile>The data structure talked about is a *list* and * ['one','two'].append('e.g. a string') * is one of the list methods.So it can be written like this:a_result_container_aka_simply_a_list =  [ ]a_result_container_aka_simply_a_list.append('something')print a_result_container_aka_simply_a_listIn general, the shorter and more descriptive a variable name is, the better.You can learn more about Python's data structures and the basic concepts of programming using the two books that I've found most useful - of course there are many more other good books that can be used.These books are:1. "Learn to Program" by Alan Gauld. It's more tutorial-like in style than the next one:2. "How to Think Like a Computer Scientist" by Jeffrey Elkner, Allen B. Downey and Chris Meyers.It's more like a school textbook with exercises at the end of each chapter and chapter 9 is called "Lists".I've used them both to look at the same concepts from different perspectives because Alan's book gives more information about programming in general while the "How to Think..." is more dry, monotonous and impersonal which can be tiring at times."The Python Tutorial" by Guido van Rossum is okay too (it's short and comprehensive) but it's mainly directed to experienced programmers who can already program in at least one language - at least that's my impression.Regards,Piotr>> On Thu, Jul 15, 2010 at 12:58 PM, Emile van Sebille   >> wrote:> On 7/15/2010 11:32 AM Mary Morris said...>>   Hi, I'm working on a program that parses through all of our source code   at my office and i need to get my code to print a list of the decorators.  I used a find(@) to locate all the decorators, but I need to assign them to a variable somehow to get it to print a list. How do I do this? How do I assign a variable to all the indexed strings after the @ symbol?>>> So, decorator lines start with an '@'.  Source files end in '.py'.>> Pseudo code could be:>>> >>> initialize result container>> with each sourcefilename in globbed list:>>>   for eachline in opened(sourcefilename):>>> if line.startswith('@'):>>>   append [sourcefilename, line] to result>> # print it>> for eachline in result:>>>   print eachline___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] append, list and variables

2010-07-16 Thread Steven D'Aprano
On Sat, 17 Jul 2010 05:44:07 am pk wrote:

> In general, the shorter and more descriptive a variable name is, 
> the better.

That's a generalisation that is contradictory. Short works against 
descriptive. Compare:

n  # nice and short
number_of_widgets_ordered  # nice and descriptive, if a bit wordy
widgets_ordered  # a happy medium

Which is appropriate depends on the context. Generally, descriptive 
names are self-documenting and are to be preferred, but it is possible 
to overdo it:

def multiply_two_numbers_and_add_one(
first_number_to_multiply_by, second_number_to_multiply_by
):
return first_number_to_multiply_by*second_number_to_multiply_by + 1


The more terse version is simple enough to understand:

def mult_plus_one(x, y):
return x*y + 1



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


[Tutor] now = ctime()[11:20]

2010-07-16 Thread Richard D. Moores
Please see 

Foolishly, without thinking it through, I expected the 2 prints to
show different times. I understood right away why they were identical,
but then I began to wonder how to create an "alias" for
"ctime()[11:20]" so I wouldn't have to keep typing or pasting it.
"now" would be fine. But how to get it to execute ctime()?

Thanks,

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