Re: [Tutor] Flip the coin 10x and count heads and tails: It works now!

2013-05-25 Thread Robert Sjoblom
On 25 May 2013 14:42, Ken G. wrote: > May I suggest that instead of: > how about: > > flips = heads = tails = 0 > > Ken How about flips = heads = 0 tails can then be calculated from flips - heads. -- best regards, Robert S. ___ Tutor maillist - Tutor@

Re: [Tutor] keyboard interrupt

2013-05-24 Thread Robert Sjoblom
On 25 May 2013 04:19, Steven D'Aprano wrote: > You can edit *other* people's questions and answers??!??!?? > > What. The. Hell. Yes; I think that the idea is that it allows people to fix spelling errors and/or reference mistakes, or maybe add things to clarify something that the answer glossed ov

Re: [Tutor] Python Programming for the Absolute Beginner

2013-05-15 Thread Robert Sjoblom
> I'm working through the Book Python Programming for the Absolute Beginner and > am wondering if you could help me out with the coding to certain > Challenges at the end of the book, specifically chapter 7 challenges 1 and 2 > and chapter 8 challenges 1 and 3. Since I personally don't have that

[Tutor] Dictionaries and multiple keys/values

2013-03-25 Thread Robert Sjoblom
Hi again, Tutor List. I am trying to figure out a problem I've run into. Let me first say that this is an assignment, so please don't give me any answers, but just nudge me in the general direction. So the task is this: from a text file, populate three different dictionaries with various informati

Re: [Tutor] (no subject)

2013-03-24 Thread Robert Sjoblom
On 25 March 2013 01:13, Mandi Seger wrote: > Hello, everyone, > > I am looking for suggestions on a beginner's book for learning Python. I > have a nursing background with basic science and math education. I have no > programming experience in any computer language. Head First Python or Head Firs

Re: [Tutor] Overriding equality tests in Python

2013-03-23 Thread Robert Sjoblom
> As I said, I don't really understand why a roulette outcome has a name in > the first place, but given that it does, I don't any problem with comparing > the names directly. Still, I would probably write it as an __eq__ method, > since it's easier to write a == b than a.name == b.name. I figured

[Tutor] Overriding equality tests in Python

2013-03-22 Thread Robert Sjoblom
Hi list. I'll preface this by saying that I am very grateful for all of you, and thank you in advance to anyone that answers. I'm currently working on a roulette simulator, because it seemed like fun. I found out I needed a way to compare two different outcomes, and it was suggested to me that I s

Re: [Tutor] Importing data from a file.

2013-03-21 Thread Robert Sjoblom
>> 3. Are there defined procedures for doing the required processing? > > If you meant conversion functions, int() and float() are examples of > those. You of course (most of the times) have to make use of string > manipulation functions (strip(), rstrip(), etc) to extract the exact > data item yo

Re: [Tutor] Help

2013-03-20 Thread Robert Sjoblom
On Mar 20, 2013 10:49 p.m., "xDog Walker" wrote: > > On Wednesday 2013 March 20 13:39, Robert Sjoblom wrote: > > A word of advice: next is a keyword in python > > ~/Packages/Python/Notable-0.1.5b> python > Python 2.5 (r25:51908, May 25 2007, 16:14:04) > [

Re: [Tutor] Help

2013-03-20 Thread Robert Sjoblom
> Hello, I am a beginning python student and I am having trouble with a > program I am writing. Hello, and welcome. Since you don't say if this is an assignment or not, I will just point you in the right direction, and point out a few things you might make use of. > def B1(): > period = "." You

Re: [Tutor] Loop Exception Handles

2013-03-15 Thread Robert Sjoblom
On 16 March 2013 05:08, Vincent Balmori wrote: > I am trying to loop a simple exception. I tried to put a while loop, but I > keep getting syntax issues. I also tried to alternatively use something on > the lines of "while number != int" also with no avail. It would help if you: a) didn't send HTM

Re: [Tutor] converting upper case to lowercase and vice-versa

2013-03-15 Thread Robert Sjoblom
> What is the correct syntax to covert English characters from uppercase to > lowercase and from lowercase to uppercase? > s.upper() and s.lower() -- best regards, Robert S. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription

Re: [Tutor] Need help with python keyboard press/navigation commands

2013-03-12 Thread Robert Sjoblom
> Finally, from a user experience point of view, it might be more logical to > make the keys w,a,s,z North, West,East and South respectively since its a > more logical correspondence to the compass points (assuming a standard > QWERTY keyboard layout). Most games use WASD, so user experience would

Re: [Tutor] There's a Programmer in Me

2013-02-26 Thread Robert Sjoblom
>> Umm. No. Sorry, Mark, but that site and the core-mentorship list it >> advertises are intended for progammers who want to be helped in the >> development *of* Python, not development *in* Python. Ie, otherwise >> experienced programmers who are unfamiliar with the Python codebase. >> >> TJG >> >

Re: [Tutor] getting and using information dict objects

2013-02-23 Thread Robert Sjoblom
> I am fairly sure i am querying the FRED API, but i am unsure how to > _access and use_ the dict objects that it is returning. For example, > how would i just print out values? If it's a dict object, the standard dictionary behavior and methods should work. I've not looked closely at the FRED API

Re: [Tutor] object attribute validation

2013-02-22 Thread Robert Sjoblom
> I would like to validate data attributes before the object is instantiated > or any changes thereafter. For example, following is a simple Person class > with name and age attributes. [snip] Following is my > example code: > class Person(object): > def __init__(self,name,age): > self.name

Re: [Tutor] following on

2013-02-19 Thread Robert Sjoblom
> Could the experts, please, recommend a beginner's book to learn the > principles of good programming? I don't know about expert, but I found the Head First Lab's approach to be really good. The Python book is structured like so: -Lists introduction -(PyPi)/creating modules -- this I hope has bee

Re: [Tutor] following on

2013-02-18 Thread Robert Sjoblom
>> i sort of heard about a stack its a C/C++ thing i think? > > A stack is fundamental to modern programming languages. The only two > machines I've used that didn't have a stack implemented at the machine level > were the CDC 6000 series, and the IBM 360. Both products of the 60's. A while back

Re: [Tutor] Python Programming for Absolute Beginner

2013-01-02 Thread Robert Sjoblom
On Jan 3, 2013 2:22 a.m., "Conor Grevlos" wrote: > > I downloaded the python source folder, with chapters 1 through 12 I think. But it just opens up the program that is already built, not one that shows me the code. Open the files in an editor of your choice, don't run them. _

Re: [Tutor] Teaching an 8-year-old programming.

2012-05-20 Thread Robert Sjoblom
>> I am currently thinking about "Invent Your Own Computer Games with >> Python" by Al Sweigart. [snip] >> Has anyone experience using this book? "Snake wrangling for kids" is pretty good for teaching Python; it's also free (which is a bonus): http://www.briggs.net.nz/snake-wrangling-for-kids.html

Re: [Tutor] question about listing variables defined since session started

2012-04-30 Thread Robert Sjoblom
> What's "who and whos"? They're matlab functions: who lists the variables currently in the workspace. whos lists the current variables and their sizes and types. It also reports the totals for sizes. -- best regards, Robert S. ___ Tutor maillist - Tu

Re: [Tutor] question about listing variables defined since session started

2012-04-30 Thread Robert Sjoblom
On 30 April 2012 23:25, Comer Duncan wrote: > Hi, > > I have a newbie type question.  Say I have started a python (or > ipython) session and have done some imports and have also defined some > new variables since the session started.  So, I have in my current > namespace a bunch of things. Suppose

Re: [Tutor] Lists and While Loops

2012-03-28 Thread Robert Sjoblom
> I can't figure out > 1) How to remove "y" from the list and continue the loop; when I use .remove > etc. it runs once then give me the error that "y" is not in the list. > > I imagine the answer is quite simple I'm just getting really frustrated > trying to get this done any advice is appreciated

Re: [Tutor] Finding a specific line in a body of text

2012-03-11 Thread Robert Sjoblom
> You haven't shown us the critical part: how are you getting the lines in > the first place? Ah, yes -- with open(address, "r", encoding="cp1252") as instream: for line in instream: > (Also, you shouldn't shadow built-ins like list as you do above, unless > you know what you are doing. If yo

[Tutor] Finding a specific line in a body of text

2012-03-11 Thread Robert Sjoblom
I'm sorry if the subject is vague, but I can't really explain it very well. I've been away from programming for a while now (I got a daughter and a year after that a son, so I've been busy with family matters). As such, my skills are definitely rusty. In the file I'm parsing, I'm looking for speci

Re: [Tutor] UnicodeEncodeError: 'cp932' codec can't encode character '\xe9' in position

2012-03-10 Thread Robert Sjoblom
> You can "solve" the problem by pretending the input file is also cp932 when > you open it. That way you'll get the wrong characters, but no errors. So I tried that: Traceback (most recent call last): File "C:\Users\Azaz\Desktop\CK2 Map Painter\Parser\test parser.py", line 6, in text = alph

[Tutor] UnicodeEncodeError: 'cp932' codec can't encode character '\xe9' in position

2012-03-10 Thread Robert Sjoblom
Okay, so here's a fun one. Since I'm on a japanese locale my native encoding is cp932. I was thinking of writing a parser for a bunch of text files, but I stumbled on even printing the contents due to ... something. I don't know what encoding the text file uses, which isn't helping my case either (

Re: [Tutor] Refactoring

2012-03-08 Thread Robert Sjoblom
> Hi, >   I have been hearing this refactoring of code. Well does it  have > any thing like this in Python and if it is then what is it all about. > Thanks. > Regards, > Ejaj Refactoring is just a way of restructuring code. It can be breaking code apart to more logical pieces -- moving parts of a

Re: [Tutor] new to programming and wondering about an IDE for Python on Linux

2012-02-27 Thread Robert Sjoblom
>> I'd appreciate any feedback on this and good tutorials or books on >> Python 3 and the IDEs suggested. There are many available and I'm >> wondering what you as users find effective. I fiddled a bit with the Eric Python IDE; Eric5 for Python3 and Eric4 for Python2; overall I'd say that Eclipse

Re: [Tutor] Help with Python Program

2012-02-26 Thread Robert Sjoblom
> import random #import random number generator module > target = random.randint(1,100) #generates random number between 1 and 100 > guess = float(raw_input('pick a number between 1 and 100')) > while guess != target: >    if guess < target: print 'too low' >    elif guess > target: print 'too high

Re: [Tutor] __name__=='__main__'

2012-02-20 Thread Robert Sjoblom
> I am having some trouble understanding how to use __name__== '__main__'. Can > you please give me some insight? if __name__ == '__main__': allows you to specify code that will only be run if you run the actual script it's in; anything in the if block won't be run if you import the module. >Also

Re: [Tutor] Debugging While Loops for Control

2012-02-17 Thread Robert Sjoblom
>> class Card(object): >>        def __init__(self): >>                self.score = self.deal() >> >>        def deal(self): >>                """deal a card from 1 to 52 and return it's points""" >>                return self.getValue(int(math.floor(random.uniform(1, >> 52 > > I think you only

Re: [Tutor] Still the Python Challenge - Conclusion

2012-01-05 Thread Robert Sjoblom
On 5 January 2012 19:41, Joaquim Santos wrote: > Hi List! [...] > This is my script (I know that I only verify a small range but it > works for what I want for now...) > > import string > > def decrypt(cypheredText, shiftedCypherNumber): >    ''' > This function will take two arguments. The first

Re: [Tutor] Parse multi line with re module.

2012-01-03 Thread Robert Sjoblom
On 3 January 2012 16:21, Joel Goldstick wrote: > -- Joel, when you start your emails with this (two dashes) some email readers (gmail among them) will think you're ending your email; I have to expand your post because it thinks that what is hidden is the signature. Just thought you should know.

Re: [Tutor] reset password program

2011-12-16 Thread Robert Sjoblom
> Some improvements to think about, in order of least secure (easiest) to most > secure (hardest). > > (1) "my secret password.txt" is a crappy name. Is there a better name? I'm going to go with "EULA.txt"; the reasons should be obvious. -- best regards, Robert S. ___

Re: [Tutor] [TUTOR]Code Deciphering

2011-12-15 Thread Robert Sjoblom
On 15 December 2011 23:37, Calle wrote: > -Ursprungligt meddelande- From: Robert Sjoblom > Sent: Thursday, December 15, 2011 10:34 PM > To: Calle > Cc: tutor@python.org > Subject: Re: [Tutor] [TUTOR]Code Deciphering > > >> I was wondering, how do you use Python

Re: [Tutor] [TUTOR]Code Deciphering

2011-12-15 Thread Robert Sjoblom
> I was wondering, how do you use Python to decipher codes? It feels like it > should be pretty simple, but I haven't found any tutorials about it yet. What kind of codes? Or do you mean ciphers? Generally speaking, a code represent letters or numbers in transmitting a message. In other words, a c

[Tutor] timeit() help

2011-12-15 Thread Robert Sjoblom
So, it turns out that my ISP blocked Project Euler, so instead of working on my next problem, I polished Problem 4 a bit: >A palindromic number reads the same both ways. The largest palindrome made >from the product of two 2-digit numbers is 9009 = 91 × 99. >Find the largest palindrome made from

Re: [Tutor] where I am going wrong?

2011-12-14 Thread Robert Sjoblom
surya k wrote: > This is a project Euler puzzle. http://projecteuler.net/problem=30 > I applied brute force way and here is my codek=0for p in range(1,10): > for q in range(0,10): for r in range(0,10): >for s in range(0,10):

Re: [Tutor] Running a script!

2011-12-12 Thread Robert Sjoblom
On 12 December 2011 11:59, Bulent Arikan wrote: > Thank you Dax! That was it! Now I can run the script. > > Cheers, > Bulent You don't have to submit the entire digest when you're replying; trim it down to what you're actually replying to. Also, please avoid posting your reply on top -- it makes

Re: [Tutor] how to handle big numbers

2011-12-09 Thread Robert Sjoblom
> There are other approaches that may bear looking at, like the SciPy library. >  But first we'd need to know just what you need with this factorial. Wouldn't a prime swing implementation be the absolutely fastest? Something like this: http://en.literateprograms.org/Special:Downloadcode/Factorials

Re: [Tutor] Python Saved the Day

2011-12-04 Thread Robert Sjoblom
I had a situation where there were 300+ files needed to be renamed to standardized naming; the problem was that each group that had worked on the project had their own naming convention and group tag. One group had date_number_subnumber_grouptag where others might have grouptag_date_number_subnumbe

Re: [Tutor] Prime Factorization Tool

2011-12-01 Thread Robert Sjoblom
> So you can roughly double the speed of your function by skipping even > numbers other than two. Remember that 2 itself is prime, but any other > multiple of 2 is not. Take that test outside of the loop, and then loop over > every second number starting with 3. > So, if I understood this right, m

Re: [Tutor] Prime Factorization Tool

2011-12-01 Thread Robert Sjoblom
> from math import sqrt > > def isprime(n, factor): >    if n == 1: >        return False >    for x in range(2, round(sqrt(n))): Ooops, this should obviously read for x in range(factor, round(sqrt(n))): best regards, Robert S. ___ Tutor maillist - Tut

Re: [Tutor] Prime Factorization Tool

2011-12-01 Thread Robert Sjoblom
> Well, there are really only a couple of optimizations that you could make. > That's the nice (bad?) thing about primes - you really only *can* brute > force a solution. That's why nice things like encryption exist. Yes, I know that; perhaps I was unclear but my issues with brute force are for sol

[Tutor] Prime Factorization Tool

2011-12-01 Thread Robert Sjoblom
So I've recently started poking at the Project Euler site, because I feel that I need to practice writing code. For those of you interested in solving the problems on your own I advice you to not read this, as it will spoil the solution. Problem 3 is this: The prime factors of 13195 are 5, 7, 13 a

Re: [Tutor] Hello again. Still the same problem, different question.

2011-11-12 Thread Robert Sjoblom
On 12 November 2011 07:27, wrote: > Send Tutor mailing list submissions to >        tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit >        http://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to >        tutor-r

Re: [Tutor] 6 random numbers

2011-10-17 Thread Robert Sjoblom
>     print random.randrange(1,42) > If you want to collect the intermediate results, either store them in a > list: > > results = [] > for i in range(6): >     results.append(random.randrange(1,42)) Gmail has removed the "Reply All" function for some ABSOLUTELY RIDICULOUS REASON, so I think peopl

Re: [Tutor] 6 random numbers

2011-10-16 Thread Robert Sjoblom
>> hello all, >> anyone know how i would go about printing 6 random numbers, i know i could >> copy and paste 6 times (which would work) but i was thinking about a while >> loop, ie. while lottery_numbers.count is <7. >> Is it possible to code this? is it possible to count random variables? i am

Re: [Tutor] Running a loop

2011-10-15 Thread Robert Sjoblom
> Subject: [Tutor] Running a loop > I am using Windows 7 and python 3.1. This is a block from a slot machine > code. It takes the random generated words and indicates if it wins or loses. > I can't figure out why it wants to print the last print statement 'Loser' no > matter if the elif statements

Re: [Tutor] Finding the differences between two lists

2011-08-25 Thread Robert Sjoblom
> shantanoo, Andre, and Robert: > > All of your solutions seem to work (and thank you for the tips!), however, > with each solution there seems to be 2 MACs that should not be in the > results. > > 00:1C:14:BA:D9:E9 and > 00:16:3E:EB:04:D9 > > should not be be turning up in the results because they

Re: [Tutor] Finding the differences between two lists

2011-08-25 Thread Robert Sjoblom
> Scenario: I have a list of MAC addresses that are known and good, and am > comparing it to a list of MACs found in a scan.  I want to weed out the > those which are unknown.  I am using IDLE (Python 2.7) on Windows, and all > files are in the same directory. > > Code: > > scanResults = open('scan

Re: [Tutor] Help with if-elif-else structure

2011-08-25 Thread Robert Sjoblom
>> #assuming target number 15 >> roll = (result, initial_mins, initial_max) > I'd forget the tuple and just use the names, > it is more readable that way... >if result > 15: >if initial_mins >= 2:... >elif initial_max >=2:... > But otherwise it seems to reflect the rules as you've writte

[Tutor] Help with if-elif-else structure

2011-08-25 Thread Robert Sjoblom
I've written a function that rolls (standard) dice. There are a few special cases though: Any sixes rolled are removed and 2*number of sixes new dice are rolled in their place. Initial roll is important to keep track of. I've solved it with the following function: from random import randint def

Re: [Tutor] issues with urllib and loading a webpage

2011-08-23 Thread Robert Sjoblom
>> Are you using Python 3 and urllib, and not using httplib2? Because I >> honestly can't get urllib.request.urlopen to work with >> http://www.boursorama.com/ -- I only get b'' from there. > > Yes, Python 3.2 which version one are you using? I tried both with > debug and without. Python 3.2.1 64

Re: [Tutor] issues with urllib and loading a webpage.

2011-08-23 Thread Robert Sjoblom
>Don't know, works fine for me.. > >Greets >Sander Are you using Python 3 and urllib, and not using httplib2? Because I honestly can't get urllib.request.urlopen to work with http://www.boursorama.com/ -- I only get b'' from there. best regards, Robert S. _

[Tutor] issues with urllib and loading a webpage.

2011-08-23 Thread Robert Sjoblom
So, an issue regarding urllib (python 3) came up earlier. I solved it by using httplib2 instead, but I'm rather curious as to why urllib wouldn't work. Here's the code I'm working with: from http.client import HTTPConnection HTTPConnection.debuglevel = 1 from urllib.request import urlopen url =

Re: [Tutor] methods vs. functions

2011-08-22 Thread Robert Sjoblom
> Can someone please explain the difference between methods and functions? I've heard the explanation "A cow is an animal but an animal is not necessarily a cow." used to describe the difference between methods and functions (ie, all methods are functions, but not all functions are methods). Obviou

Re: [Tutor] Tkinter: no module named messagebox (brandon w)

2011-08-14 Thread Robert Sjoblom
> I have tried to follow the tutorial I found here: > > Python 2.7 Tutorial > http://www.youtube.com/watch?v=uh6AdDX7K7U > > This is what I have done so far: > > #!/usr/bin/python > > from Tkinter import * > import Tkinter.MessageBox I figured I might as well, given how I recently had to learn abo

Re: [Tutor] commandline unable to read numbers?

2011-08-07 Thread Robert Sjoblom
> I think you are on the right track: Python 3.2's input() has a nasty bug on > Windows (http://bugs.python.org/issue11272). If you repeat the following in > your interactive interpreter (invoked from the commmandline) > input() > 123 > '123' > > and see '123\r' instead of just '123' you are a

Re: [Tutor] commandline unable to read numbers? (Steven D'Aprano)

2011-08-07 Thread Robert Sjoblom
> Robert Sjoblom wrote: >> I have a quite odd problem, and I've come across it before but >> probably ignored it at the time because I had other concerns. I've >> tried googling for the answer but haven't really come closer to >> solving it. >> This

[Tutor] commandline unable to read numbers?

2011-08-06 Thread Robert Sjoblom
I have a quite odd problem, and I've come across it before but probably ignored it at the time because I had other concerns. I've tried googling for the answer but haven't really come closer to solving it. This is what happens: C:\[path]\nester>C:\Python32\python.ex e setup.py register running regi

[Tutor] [OT] Re: Floating Point Crazines

2011-06-12 Thread Robert Sjoblom
>> * Or you just get used to the fact that some numbers are not exact in >> floating point. > > This got me thinking. How many decimal places do you need to > accurately, say, aim a laser somewhere in a 180 degree arc accurately > enough to hit a dime on the surface of the moon? > > Alan In short:

Re: [Tutor] Strategy to read a redirecting html page

2011-06-02 Thread Robert Sjoblom
On 2 June 2011 22:50, Brett Ritter wrote: > On Thu, Jun 2, 2011 at 4:06 PM, Robert Sjoblom > wrote: >> Python already has the urllib/urllib2 package that automatically >> follow redirects, so I don't see why you'd need a 3rd-party module to >> deal with it? Wh

Re: [Tutor] Strategy to read a redirecting html page

2011-06-02 Thread Robert Sjoblom
> When you hit the page and you get an HTTP redirect code back (say, > 302), you will need to make another call to the URL specified in the > "Location" parameter in the response headers. Then you retrieve that > new page and you can check you got an acceptable HTTP response code > (such as 200) an

Re: [Tutor] Help with understanding classes

2011-05-22 Thread Robert Sjoblom
> That's pretty much all you need to know to start using objects. There's > a lot more though: inheritance, class methods and static methods (as > opposed to ordinary methods), properties, descriptors (advanced!), > slots, and more. But one step at a time. > > Any questions, don't hesitate to ask!

Re: [Tutor] if value not in dictionary, do a?

2011-03-25 Thread Robert Sjoblom
-- Hugo Arts wrote -- >Why are you asking for the user to enter a key? you're iterating over >all keys in the dictionary, so there's no need to ask the user for >keys, you already know them. Why not do this: >b = int(input("Enter value for key %s: " % key)) >dictionary[key] = b I have a great an

[Tutor] if value not in dictionary, do a?

2011-03-25 Thread Robert Sjoblom
Hi again, list! A quick question about dictionary behaviour. I have a dictionary of keys, and the user should be able to enter values into said dictionary. My idea was this: def addData(key, value): dictionary[key] += int(value) return None dictionary = {"a":0, "b":0, "c":0, "d":0} for k