Re: [Tutor] help with data insert into Access table

2014-01-29 Thread Peter Otten
Ahmed, Shakir wrote: > I am trying to insert a record in the access table, the value has a quote > and could not insert the record. Any idea how I can insert records like > this quotes. > cursor.execute("INSERT INTO PicsPostInfo(Pics_name) values ('Site Name's > Harbor.JPG')") Traceback (most rec

Re: [Tutor] When is = a copy and when is it an alias

2014-01-27 Thread Peter Otten
Denis Heidtmann wrote: > Running python 2.7 in linux > > Below are two extremes. Can I get some guidance on this? a=zeros((2,3),dtype=int) b=a a[:,0]=[1,2] a > array([[1, 0, 0], >[2, 0, 0]]) b > array([[1, 0, 0], >[2, 0, 0]]) a=2 a > 2 b >

Re: [Tutor] Iterator vs. iterable cheatsheet, was Re: iter class

2014-01-24 Thread Peter Otten
spir wrote: > On 01/24/2014 10:22 AM, Peter Otten wrote: >> >> There's an odd outlier that I probably shouldn't tell you about [...] > > I guess there is a whole class of outliers; not really sure how to > classify them. I think you are focusing on the de

Re: [Tutor] code works in windows command but not ubuntu terminal

2014-01-24 Thread Peter Otten
Tobias Quezada wrote: > hello community,i am a newbie to python and program in general. > the script below works in python 2.7.3 on windows but not in the python > 2.7.3 ubuntu terminal. > fp=open("prez.dat","r")>>>x=fp.read>>>(print(x)***i used fp for file pointer.I am using windows 7 an

[Tutor] Iterator vs. iterable cheatsheet, was Re: iter class

2014-01-24 Thread Peter Otten
+--+++ | | __iter__ | __next__ | +--+++ | iterable | return an iterator | not available | +--+++ | i

Re: [Tutor] iter class

2014-01-23 Thread Peter Otten
Keith Winston wrote: > On Thu, Jan 23, 2014 at 12:21 AM, Devin Jeanpierre > wrote: >> in Python 3, it should be __next__, not next. > > Ah! That's it! Thanks!!! > >> I'd suggest staying away from any old blog posts and articles, unless >> you'd care to learn Python 2.x instead of 3.x. ;) > > Y

Re: [Tutor] how run it on python 3

2014-01-20 Thread Peter Otten
S Tareq wrote: > this is the coding that i am trying to run it on python 3.3. the original > coding was made on python 2.7 however i have made some changes to the > coding to make it work on python 3.3. the changes that i have made on > brackets and raw_input to input. the coding does not load th

Re: [Tutor] string indexing

2014-01-19 Thread Peter Otten
rahmad akbar wrote: > hey guys, super noob here, i am trying to understand the following code > from google tutorial which i failed to comprehend > > #code start > # E. not_bad > # Given a string, find the first appearance of the > # substring 'not' and 'bad'. If the 'bad' follows > # the 'not',

Re: [Tutor] Naming variables

2014-01-19 Thread Peter Otten
Pierre Dagenais wrote: > I wish to fill a list called years[] with a hundred lists called > year1900[], year1901[], year1902[], ..., year1999[]. That is too much > typing of course. Any way of doing this in a loop? I've tried stuff like > ("year" + str(1900)) = [0,0] but nothing works. > Any solut

Re: [Tutor] ValueError: could not convert string to float: '13,2'

2014-01-19 Thread Peter Otten
Pierre Dagenais wrote: > > > On 13-12-31 04:09 PM, Keith Winston wrote: >> Hi PierreD, I think if you iterate over your strings with something like >> this, it will do what you want, if I understand correctly (snum is your >> string number, like "123,321"): >> >> fnum = float(snum.replace(",",

Re: [Tutor] iterators

2014-01-18 Thread Peter Otten
Keith Winston wrote: > I don't really get iterators. I saw an interesting example on > Stackoverflow, something like > > with open('workfile', 'r') as f: > for a, b, c in zip(f, f, f): > > > And this iterated through a, b, c assigned to 3 consecutive lines of > the file as it iterates t

Re: [Tutor] Interactive escape sequences

2014-01-14 Thread Peter Otten
Christian Alexander wrote: > Hello Tutorians, > > Why does the interactive prompt not recognize escape sequences in strings? > It only works correctly if I use the print function in python 3. > "Hello\nWorld" > "Hello\nWorld" The way python shows objects in the interactive interpreter has

Re: [Tutor] another better way to do this ?

2014-01-13 Thread Peter Otten
Alan Gauld wrote: > On 13/01/14 18:22, Peter Otten wrote: >> Peter Otten wrote: > >> In the mean time here is my candidate: >> >> def test(a, b): >> a = iter(a) >> return all(c in a for c in b) > > That's pretty close to my original

Re: [Tutor] another better way to do this ?

2014-01-13 Thread Peter Otten
Peter Otten wrote: > Emile van Sebille wrote: > >> On 01/12/2014 12:21 PM, Peter Otten wrote: >> >>>>>> test("axbxc", "abc") >>> True >>>>>> test("abbxc", "abc") >>> False >>&g

Re: [Tutor] another better way to do this ?

2014-01-12 Thread Peter Otten
Emile van Sebille wrote: > On 01/12/2014 12:21 PM, Peter Otten wrote: > >>>>> test("axbxc", "abc") >> True >>>>> test("abbxc", "abc") >> False >> >> Is the second result desired? > &g

Re: [Tutor] another better way to do this ?

2014-01-12 Thread Peter Otten
Emile van Sebille wrote: > On 01/12/2014 06:43 AM, Dave Angel wrote: >> Roelof Wobben Wrote in message: >> >> That documentation says nothing about order. And the test cases >> specifically contradict it. >> >> so try >> >> if set (b) <= set (a): > > or, as the OP specified, if order is rel

Re: [Tutor] another better way to do this ?

2014-01-12 Thread Peter Otten
Alan Gauld wrote: > On 12/01/14 08:12, Roelof Wobben wrote: > >> # Write a Python procedure fix_machine to take 2 string inputs >> # and returns the 2nd input string as the output if all of its >> # characters can be found in the 1st input string and "Give me >> # something that's not useless nex

Re: [Tutor] arrangement of datafile

2014-01-09 Thread Peter Otten
Amrita Kumari wrote: > On 17th Dec. I posted one question, how to arrange datafile in a > particular fashion so that I can have only residue no. and chemical > shift value of the atom as: > 1 H=nil > 2 H=8.8500 > 3 H=8.7530 > 4 H=7.9100 > 5 H=7.4450 >

Re: [Tutor] python 3.3 split method confusion

2014-01-08 Thread Peter Otten
Danny Yoo wrote: > One of the common cases for split() is to break a line into a list of > words, for example. > > # 'hello this is a test'.split() > ['hello', 'this', 'is', 'a', 'test'] > # > > The Standard Library can

Re: [Tutor] Chutes & Ladders

2013-12-23 Thread Peter Otten
Keith Winston wrote: > On Sun, Dec 22, 2013 at 3:04 PM, wrote: > >> >> games = [p1.gameset(gamecount) for _ in range(multicount)] > > > So Peter gave me a list of suggesttions, all of which I've incorporated > and gotten running, and it's been instruct

Re: [Tutor] Chutes & Ladders

2013-12-23 Thread Peter Otten
Keith Winston wrote: > On Sun, Dec 22, 2013 at 3:04 PM, wrote: > >> To sum it up: I like what you have, my hints are all about very minor >> points >> :) >> > > > Peter, that's a bunch of great suggestions, I knew there were a lot of > places

Re: [Tutor] Chutes & Ladders

2013-12-22 Thread Peter Otten
Keith Winston wrote: > I've put together my first small program. It's a simulation of the game > Chutes & Ladders. It plays the game and amasses an array of ([multicount] > [gamecount]) size, and then crunches simple stats on the average moves, > chutes, and ladders for all games in each high-lev

Re: [Tutor] Stats packages in Mint 16

2013-12-22 Thread Peter Otten
Keith Winston wrote: > I want to play with some stats, but I am having trouble installing numpy > on mint 16 Petra/Saucy. Is there some way to do it, or some alternative, > or do I not know what I'm talking about (largely true in this case)? What did you try? I don't have Mint 16, but I'd expect

Re: [Tutor] Getting Started

2013-12-19 Thread Peter Otten
Oscar Benjamin wrote: > I have to qualify my > statement with this caveat to discourage pedants from correcting me. Correction: no practical way to discourage pedants from correcting anyone has been found yet. Your statement has no effect (at best). ;)

Re: [Tutor] set locals

2013-12-18 Thread Peter Otten
spir wrote: > Hello, > > is it at all possible to set new vars (or any symbol) into an existing > scope (typically locals())? locals() normally contains a copy of the current namespace as a dict. Setting items is possible but only alters the dict and has no effect on the original namespace: >

Re: [Tutor] arrangement of datafile

2013-12-17 Thread Peter Otten
Amrita Kumari wrote: > Hi, > > I am new in programming and want to try Python programming (which is > simple and easy to learn) to solve one problem: in which > I have various long file like this: > > 1 GLY HA2=3.7850 HA3=3.9130 > 2 SER H=8.8500 HA=4.3370 N=115.7570 > 3 LYS H=8.7530 HA=4.0340 HB

Re: [Tutor] Built In Functions

2013-12-17 Thread Peter Otten
Rafael Knuth wrote: > I just wrote a unittest for this function here: > > def PositiveCalculator(*summands): > if all(x > 0 for x in summands): > return sum(summands) > else: > raise ValueError("negative value") > > Here's the test (I want to test whether the function wor

Re: [Tutor] Built In Functions

2013-12-17 Thread Peter Otten
Rafael Knuth wrote: > Hej there, > >> I use any() and all() frequently. For example, suppose you have a >> function that takes a list of numbers, and they are all supposed to be >> positive. >> >> def calculate_values(numbers): >> if all(number > 0 for number in numbers): >> # do the

Re: [Tutor] Continue Statement

2013-12-16 Thread Peter Otten
Alina Campana wrote: > Hello dear tutorlist, Welcome! > I feel terribly ashamed for my bad english... > Yet I'll try to form my question: > It is about the continue statement in python.I wrote this code > i = 0while (i < 10): if i == 5: continueprint i i+=1 > What i expecte

Re: [Tutor] Built In Functions

2013-12-16 Thread Peter Otten
Rafael Knuth wrote: > Hey there, > > I am currently looking into all built in functions in Python 3.3.0, > one by one, in order to understand what each of them specifically does > (I am familiar with some of them already, but most built in functions > are still alien to me). I am working with the

Re: [Tutor] weird lambda expression -- can someone help me understand how this works

2013-12-14 Thread Peter Otten
Alan Gauld wrote: > On 14/12/13 04:19, Steven D'Aprano wrote: > >> Lambda is just syntactic sugar for a function. It is exactly the same as >> a def function, except with two limitations: >> >> - there is no name, or to be precise, the name of all lambda functions >> is the same, ""; > > Sorry,

Re: [Tutor] list comprehension equivalent to map(function, list item)

2013-12-14 Thread Peter Otten
Bo Morris wrote: > Thank you for your assistance. Based on your direction, I figured it out. > > *This... * > > def add(number): > print 1 + int(number) > > x = ['2', '4', '6', '8', '10', '12'] > > [add(item) for item in x] > > *Is the same as... * > > > def add(number): > print

Re: [Tutor] Output not legible when debugging with ipdb

2013-11-30 Thread Peter Zorn
with colored code, tab completion, etc (see http://ipython.org/ipython-doc/stable/api/generated/IPython.core.debugger.html?highlight=debugger#IPython.core.debugger) Thanks, Peter On 27.11.2013 00:24, eryksun wrote: On Tue, Nov 26, 2013 at 4:28 PM, Walter Prins wrote: honest. Regarding

Re: [Tutor] Issue w/ string input "for", "not", "while", "else" etc.

2013-11-27 Thread Peter Otten
Steven D'Aprano wrote: > On Wed, Nov 27, 2013 at 09:45:20AM +0100, Peter Otten wrote: > >> I took the freedom to report it myself: >> >> http://bugs.python.org/issue19808 > > Thanks for reporting the issue! > > > [off-topic] > > You might

Re: [Tutor] Issue w/ string input "for", "not", "while", "else" etc.

2013-11-27 Thread Peter Otten
Rafael Knuth wrote: > simple issue I couldn't find a solution for: > > YourName = input(str("What is your name?")) > print("Hello", YourName) > > When executing the program, in case the user input is "for", "not", > "True", "while" Python interprets that as a command and changes the > input's co

Re: [Tutor] Issue w/ string input "for", "not", "while", "else" etc.

2013-11-26 Thread Peter Otten
Alan Gauld wrote: > On 26/11/13 16:49, Peter Otten wrote: > >>> When executing the program, in case the user input is "for", "not", >>> "True", "while" Python interprets that as a command and changes the >>> input'

Re: [Tutor] Issue w/ string input "for", "not", "while", "else" etc.

2013-11-26 Thread Peter Otten
Rafael Knuth wrote: > Hej there, > > simple issue I couldn't find a solution for: > > YourName = input(str("What is your name?")) > print("Hello", YourName) > > When executing the program, in case the user input is "for", "not", > "True", "while" Python interprets that as a command and changes

Re: [Tutor] Two subsequent for loops in one function

2013-11-22 Thread Peter Otten
Rafael Knuth wrote: > Hej there, > > newbie question: I struggle to understand what exactly those two > subsequent for loops in the program below do (Python 3.3.0): > > for x in range(2, 10): > for y in range(2, x): > if x % y == 0: > print(x, "equals", y, "*", x//y) >

Re: [Tutor] Sending sensible e-mail (was: Re: (no subject))

2013-11-22 Thread Peter Otten
Dominik George wrote: >> Subject: [Tutor] (no subject) > > On a side note, please learn how to send e-mail. Nik, this is a beginners' list, so please be more constructive. 久場海人, Nik may be unfriendly, but he is right; in future posts please take the time to pick a subject that gives the read

Re: [Tutor] Reading number x and printing number x+1

2013-11-22 Thread Peter Otten
G. McKinnon Ryall wrote: > I have a script that outputs results to a file (one file, reused.) I would > like to have an output file in this format > > # > (blank line) > (output from program (only one line)) > name > (T/F) > (result iteration, shortened to x.) > #-

Re: [Tutor] (no subject)

2013-11-22 Thread Peter Otten
久場海人 wrote: > Hi. I began programming literally 2 days ago. > > This is a code to setup password and confirms to make sure they both > match, and I need to know what coding I can use to loop back to specific > line to start the code over if the user were to incorrectly typed in the > password. >

Re: [Tutor] Issue w/ while loops

2013-11-21 Thread Peter Otten
Rafael Knuth wrote: > Hej there, > > I want to use a while loop in a program (version used: Python 3.3.0), > and I expect it to loop unless the user enters an integer or a > floating-point number instead of a string. > > print("TIME TRACKING") > hours_worked = input("How many hours did you work

Re: [Tutor] ideas?

2013-11-18 Thread Peter Otten
Byron Ruffin wrote: > Need a little help with finding a process for this: > > when a string of text is input, for example: abc def. > I want to have each letter shift to the right one place in the alphabet. > Thus.. > abc def would be output as bcd efg. > > Any ideas on how to do this? Have a l

Re: [Tutor] Help merge files using python

2013-11-15 Thread Peter Otten
jarod...@libero.it wrote: > Hi I want to merge many files like this: > #file1 > A 10 > B 20 > C 30 > #file2 > B 45 > Z 10 > #file1 > A 60 > B 70 > C 10 > > I want to obtain > > A 10 0 60 > B 20 45 70 > C 30 0 10 > Z 0 10 0 > > I try to do like this: > f = os.lis

Re: [Tutor] Geometric sequence

2013-11-08 Thread Peter O'Doherty
To the people who kindly replied to my question: many thanks! On 10/31/2013 06:29 PM, Danny Yoo wrote: As an aside: It shouldn't be too bad to write a "generator" for the geometric series, so that we can pick out the terms on-demand. # >>> def geometric(base):

Re: [Tutor] String representation of NULL (non type) values

2013-11-05 Thread Peter Otten
Ulrich Goebel wrote: > Hallo, > > from a SQLite database I get a value by SELECT s from... which normaly > is a string, but can be the NULL value, wich means it is not defined. To > put the value into a form (made by QT) I need a string representation. > > str(s) gives either the string itself (

Re: [Tutor] Load Entire File into memory

2013-11-04 Thread Peter Otten
Amal Thomas wrote: > Yes I have found that after loading to RAM and then reading lines by lines > saves a huge amount of time since my text files are very huge. How exactly did you find out? You should only see a speed-up if you iterate over the data at least twice.

Re: [Tutor] Dictionary from a text file

2013-10-31 Thread Peter Otten
Nitish Kunder wrote: > I have a dictionary which is in this format > for ex: > > { > '5x' : { > '50' : { > 'update' : { > 'update-from-esxi5.0-5.0_update01' : { > 'call' : Update, > 'name' : 'Update50u1', > 'release' : '15/03/12' > }, > 'update-from-esxi5.0-5.0_update02' : { > 'call' : Update, >

[Tutor] Geometric sequence

2013-10-30 Thread Peter O'Doherty
series_element if series_element > 60: break print series Many thanks, Peter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Parsing multiple lines from text file using regex

2013-10-27 Thread Peter Otten
Marc wrote: > Hi, > I am having an issue with something that would seem have an easy solution, > which escapes me. I have configuration files that I would like to parse. > The data I am having issue with is a multi-line attribute that has the > following structure: > > banner > Banner text > B

Re: [Tutor] Help please

2013-10-17 Thread Peter Otten
Alan Gauld wrote: [Ruben Pinedo] > def process_file(filename): > hist = dict() > fp = open(filename) > for line in fp: > process_line(line, hist) > return hist > > def process_line(line, hist): > line = line.replace('-', ' ') > > for word in line.split(): >

Re: [Tutor] Looking for Words - Help

2013-10-11 Thread Peter Otten
Mark Lawrence wrote: > On 11/10/2013 15:23, Peter Otten wrote: >> Alan Gauld wrote: >> >>>> Use the stripw() function we saw on individual words to make >>>> finding hits more accurate >>> >>> No idea what that means but since the assignme

Re: [Tutor] Looking for Words - Help

2013-10-11 Thread Peter Otten
Alan Gauld wrote: >> Use the stripw() function we saw on individual words to make >> finding hits more accurate > > No idea what that means but since the assignment suggests > it we should assume its correct. My crystal ball says def stripw(word): return word.strip('",.') or somesuch. > Y

Re: [Tutor] Looking for Words - Help

2013-10-11 Thread Peter Otten
Jackie Canales wrote: > Need assistance with a questions in regards to python: > 1. function occurs(name, word) which looks for a word in the file with > name name. 2. for each occurrence of the word we want to display its > context by showing the 5 words (or so) preceding and following the > occu

Re: [Tutor] docopt module: defaults appear to be ignored

2013-10-11 Thread Peter Otten
Alex Kleider wrote: > On 2013-10-09 00:29, Peter Otten wrote: >> While I did not read the documentation I did try your code: >> >> (docopt)$ cat test >> #!/usr/bin/env python >> # -*- coding : utf -8 -*- >> # file: 'test' >> "&

Re: [Tutor] docopt module: defaults appear to be ignored

2013-10-09 Thread Peter Otten
Alex Kleider wrote: > > A recent post recommended the docopt module so I've incorporated it into > the code I'm using to learn SQLite. It's not behaving as I expected. > Here's a snippet of code: > > > #!/usr/bin/env python > # -*- coding : utf -8 -*- > # file: 'test' > """Usage: test [new_data

Re: [Tutor] How to add modules?

2013-09-19 Thread Peter Otten
Naman Kothari wrote: > Can you please suggest a link from where i can download SendKeys module > for python. Also provide an explanation to add the module to my library. > PS: I am a Windows user. I'd start installing a tool called "pip". I suggest that you follow the instructions given here: h

Re: [Tutor] Field Width

2013-09-19 Thread Peter Otten
Jenny Allar wrote: > I'm only a few days in to learning Python, so please bear with me. Welcome! > I need to line up the decimals on the printed information but I cannot get > the text to look uniform at all. > print("The cost of the carpet is $", format(subtotal,'9,.2f')) > print("The

Re: [Tutor] flask/sqlite3 problem - 'OperationalError: no such table'?

2013-09-18 Thread Peter Otten
memilanuk wrote: > I'm working thru a Flask tutorial, and when I get to the portion for > querying the database (sqlite3) for the existing posts, i.e. 'SELECT * > FROM posts', I get an error that says there is no such table 'posts' in > my database. Yet I can query said db file from either the sq

Re: [Tutor] Python 2 & 3 and unittest

2013-09-04 Thread Peter Otten
Steven D'Aprano wrote: > On Thu, Sep 05, 2013 at 09:11:50AM +1000, Steven D'Aprano wrote: > >> I don't believe there is a way to make >> string literals unicode, you just have to get used to writing u"" and >> b"" strings by hand. > > Sorry, that is unclear. I meant to say, there is no way to fo

Re: [Tutor] help with postgreSQL and .csv

2013-09-03 Thread Peter Otten
Ismar Sehic wrote: > hello. Ismar, please post in plain text. The markup appears as funny stars over here. > i wrote the following code, to insert some values from a csv file to my > postgres table : > > *** > *import psycopg2* > *conn = psycopg2.connect("host = ***.***.***.*** user=**

Re: [Tutor] verb conjugations

2013-08-25 Thread Peter Otten
Duri Denoth wrote: > Hello Tutor > > I have written a program that generates verb conjugations. > > There is a loop that generates the regular forms: > > for i in range(6): > present[i] = stem + worded_present_ar[i] An alternative way to write this is present = [stem + suffix for suffix i

Re: [Tutor] How much in a "try" block?

2013-08-23 Thread Peter Otten
Alan Gauld wrote: > On 22/08/13 21:27, Chris Down wrote: > >> You can also use the "else" clause if there is stuff you want to run if >> the try block doesn't raise the caught exception, which avoids putting it >> in "try" if you don't intend to exit from the exception. > > I admit that I've nev

Re: [Tutor] mistaken about splitting expressions over lines

2013-06-25 Thread Peter Otten
eryksun wrote: > Constant folding for binary operations has a length limit of 20 for > sequences: > > >>> dis.dis(lambda: '0123456789' + '0123456789' + '0') > 1 0 LOAD_CONST 3 ('0123456789 > 0123456789') >

Re: [Tutor] mistaken about splitting expressions over lines

2013-06-25 Thread Peter Otten
Albert-Jan Roskam wrote: > ___ >>From: eryksun >>To: Jim Mooney >>Cc: tutor@python.org >>Sent: Tuesday, June 25, 2013 2:14 PM >>Subject: Re: [Tutor] mistaken about splitting expressions over lines > > > >> > a = ('this' # this way >>... ' string' ' is lon

Re: [Tutor] Need help printing a pickled data

2013-06-24 Thread Peter Otten
Matt D wrote: > On 06/24/2013 07:17 PM, Alan Gauld wrote: >> On 24/06/13 23:05, Matt D wrote: >>> I have been unable to find a way to write pickled data to text file. >> >> Probably because pickled data is not plain text. >> You need to use binary mode. However... >> >> >>> def __init__(se

Re: [Tutor] Help (Antonio Zagheni)

2013-06-24 Thread Peter Otten
Antonio Zagheni wrote: >> I am a begginer in Pythonu >> I did a function that returns a string and I want to copy this to the >> clipboard. I have tried a lot of suggestions found at Google but nothing >> works properly. Is there an easy way to do that? >> I am using Python 2.7 and Windows 7. > >

Re: [Tutor] Function Return Values (or References)

2013-06-24 Thread Peter Otten
John Steedman wrote: > Hi Tutors, > > I'm confused by the following possible contradiction. Would someone please > explain or point me to the right docs. > > FACT 1 > > "Variables in python hold references to objects." > http://en.wikipedia.org/wiki/Python_syntax_and_semantics > > FACT 2 > >>

Re: [Tutor] random.choice() problem

2013-06-23 Thread Peter Otten
Dave Angel wrote: > On 06/23/2013 02:18 AM, Jack Little wrote: >> I am trying to use random.choice for a text based game. I am using >> windows 7, 64-bit python. Here is my code: >> >> def lvl2(): >> print "COMMANDER: Who should you train with?" >> trn=random.choice(1,2) >> if trn==

Re: [Tutor] How convert an int to a string

2013-06-22 Thread Peter Otten
Jim Byrnes wrote: > I need to convert a series of digits like 060713 to a string so I can > make it look like a date 06-07-13. > > >>> a = 060713 > >>> a[:2] > Traceback (most recent call last): >File "", line 1, in > TypeError: 'int' object has no attribute '__getitem__' > >>> b = str(a)

[Tutor] "farkadoodle" or: unique global names, was Re: Data persistence problem

2013-06-22 Thread Peter Otten
Jim Mooney wrote: > dictnumfarkadoodle = listnumfarkadoodle = setnumfarkadoodle = 0 > # Since these are global I'm using words not likely to be duplicated > until I figure a different way and > # replace 'farkadoodle' with '' ;') Name clashes are generally not a problem if (1) you keep module s

Re: [Tutor] Data persistence problem

2013-06-21 Thread Peter Otten
Alan Gauld wrote: > rand_num = None > > def rand_int(): > global rand_num > if not rand_num: This will not recognize the (unlikely but possible) case that random.random() returns 0.0. So you better check for None explicitly if rand_num is None: >rand_num = int(math.ceil (

Re: [Tutor] Playing with XML

2013-06-21 Thread Peter Otten
Danilo Chilene wrote: > Hello, > > Below is my code: > > #!/bin/env python > # -*- coding: utf-8 -*- > import requests > from lxml import etree > > url = 'http://192.168.0.1/webservice.svc?wsdl' > headers = {'Content-Type': 'text/xml;charset=UTF-8', 'SOAPAction': ' > http://tempuri.org/ITServic

Re: [Tutor] Need help appending data to a logfile

2013-06-17 Thread Peter Otten
Matt D wrote: > Hey, > I wrote some simple code to write data to a logfile and it works pretty > well (thanks guys). Now my problem is that every time i run the program > the old logfile.txt is overwritten. The help() function in the interactive interpreter is a good tool hunt for help on fea

Re: [Tutor] Using __init__ to return a value

2013-06-12 Thread Peter Otten
Khalid Al-Ghamdi wrote: >1. >>> class k: >2. def __init__(self,n): >3. return n*n >4. >5. >6. >>> khalid=k(3) >7. Traceback (most recent call last): >8. File "", line 1, in >9. khalid=k(3) >10. TypeError: __init__() should retu

Re: [Tutor] Quick Question on String Compare

2013-06-01 Thread Peter Otten
ook like numbers: >>> number_strings = ["2", "20", "100", "1"] >>> sorted(number_strings, key=lambda x: (len(x), x)) ['1', '2', '20', '100'] >>> names = ["Abe", "Peter", &quo

Re: [Tutor] challenge-chapter 2

2013-05-22 Thread Peter Otten
Andrew Triplett wrote: > I am on chapter two for Python Programming working on the challenges and > the question is: > > 1. Create a list of legal and illegal variable names. Describe why each is > either legal or illegal. Next, create a list of "good" and "bad" legal > variable names. Describe w

Re: [Tutor] Hi Folks...Need help with a modified version of the Subset sum problem.

2013-05-21 Thread Peter Otten
spiff007 wrote: > Hi there Tutor folks > > I need your help with a modified version of the subset sum problem [ > http://en.wikipedia.org/wiki/Subset_sum_problem]. > > The problem i am facing is a bit hard to describe (as most complex problem > always are :D ), so please bear with my longish art

Re: [Tutor] os.getcwd() confusion

2013-05-20 Thread Peter Otten
spangled spanner wrote: > G'day, > > I have a comprehension issue here! I have made two simple scripts: > > ## script1 > > import os > > print os.getcwd() > > - > ## script 2 > > import os > > f = open('test', 'wb') > f.write(os.getcwd()) > f.close() > > ___

Re: [Tutor] Beginner level: Why doesn't my code work?

2013-05-19 Thread Peter Otten
Rafael Knuth wrote: > Thank you, I am using Python 3.3.0 [Oscar] > In Python 3 you should use input(). In Python 2 you should use > raw_input(). I'm guessing that you're using Python 2. In Python 2 the > input() function tries to evaluate whatever the user types in as if it > was Python code. Sin

Re: [Tutor] Retrieving data from a web site

2013-05-19 Thread Peter Otten
Phil wrote: > My apatite having been whetted I'm now stymied because of a Ubuntu > dependency problem during the installation of urllib3. This is listed as > a bug. Has anyone overcome this problem? > > Perhaps there's another library that I can use to download data from a > web page? You mean y

Re: [Tutor] Retrieving data from a web site

2013-05-18 Thread Peter Otten
Phil wrote: > On 18/05/13 19:25, Peter Otten wrote: >> >> Are there alternatives that give the number as plain text? > > Further investigation shows that the numbers are available if I view the > source of the page. So, all I have to do is parse the page and extract >

Re: [Tutor] Retrieving data from a web site

2013-05-18 Thread Peter Otten
Phil wrote: > On 18/05/13 16:33, Alan Gauld wrote: >> On 18/05/13 00:57, Phil wrote: >>> I'd like to "download" eight digits from a web site where the digits are >>> stored as individual graphics. Is this possible, using perhaps, one of >>> the countless number of Python modules? Is this the funct

Re: [Tutor] Python Idle Crashing

2013-05-16 Thread Peter Otten
kyle seebohm wrote: > I recently created a program that searches through a computer's drive to > make a list of all the files in that drive. However, the drive I am > attempting to parse through is extremely large and when I run my program, > it runs for about 5 or 10 minutes then proceeds to not

Re: [Tutor] Argparse functions with N parameters

2013-05-07 Thread Peter Otten
Danilo Chilene wrote: > Hello, > > I have the code below: > > import argparse > class Myclass(object): > > def foo(self): > print 'foo' > > def bar(self): > print 'bar' > > def test(self,name,place): > print name, place > > class Main(Myclass): > def _

Re: [Tutor] Raw string form variable

2013-05-05 Thread Peter Otten
Ajin Abraham wrote: > Please refer this paste: http://bpaste.net/show/vsTXLEjwTLrWjjnfmmKn/ > and suggest me the possible solutions. > Regards, Quoting the paste: > i am executing these in Python 2.7 interpreter > >>>import os > >>> os.path.join(r'C:\win\apple.exe') > #will returns me = 'C:\\win

Re: [Tutor] creating a corpus from a csv file

2013-05-04 Thread Peter Otten
Treder, Robert wrote: > I'm very new to python and am trying to figure out how to make a corpus > from a text file. I have a csv file (actually pipe '|' delimited) where > each row corresponds to a different text document. Each row contains a > communication note. Other columns correspond to categ

Re: [Tutor] Multiple search and replace?

2013-05-02 Thread Peter Otten
Andy McKenzie wrote: > Hey folks, > > I'm trying to figure out how to do something, and it feels like it > should > be possible, but I can't figure out how. What I want is to define four > expressions, like so: > > (\sNorth\s|\sN\s)(\sSouth\s|\sS\s)(\sEast\s|\sE\s)(\sWest\s|\sW\s) > > And

[Tutor] dict.iteritems() in Python3, was Re: Tutor Digest, Vol 110, Issue 117

2013-04-30 Thread Peter Otten
Prasad, Ramit wrote: > Jim Mooney wrote: >> >> > In py3.x, iteritems was replaced by .items() >> >> Interesting, since iteritems was in my book, which was "updated" for >> Py33. I guess the moral is you shouldn't trust an author 100% ;') I >> must admit, iteritems did seem awkward and annoying

[Tutor] How to zoom in matplotlib without a mouse ?

2013-04-29 Thread Peter Rowat
To "zoom" a matplotlib graph, the matplotlib docs all say "use R mouse button". But my laptop has no mouse, only a touchpad (running OSX Mountain Lion). I've tried lots of "click plus key" combinations, no luc

Re: [Tutor] Classes in multiple files - code included

2013-04-03 Thread Peter Otten
Phil wrote: > I think I must be very close now so I'll post just the code that I think > is relevant. > > This the main window class: > import satListDialog Here you are importing the module "satListDialog" > class MainWindow(QMainWindow, Ui_MainWindow): > > This is the function to show the

Re: [Tutor] IndexError: index out of bounds

2013-03-27 Thread Peter Otten
Sayan Chatterjee wrote: > Yes, when handled as a numpy array, it's working fine! > > Traceback (most recent call last): > File "ZA.py", line 59, in > if temp_za == j: > ValueError: The truth value of an array with more than one element is > ambiguous. Use a.any() or a.all() >From the atta

Re: [Tutor] IndexError: index out of bounds

2013-03-27 Thread Peter Otten
Sayan Chatterjee wrote: > Hi Walter, > Thanks a lot! > > Yes, now I get your point. append is working perfectly fine. > > Hi Peter: > > Exactly. It's very nice. Indices needn't have to be mentioned explicitly. > No explicit looping and the thing is done! &g

Re: [Tutor] IndexError: index out of bounds

2013-03-27 Thread Peter Otten
Sayan Chatterjee wrote: > When trying to print or assign array elements, getting the following > error: > > Traceback (most recent call last): > File "ZA.py", line 32, in > p_za[i] = p_initial[i] + t*K*cos(K*p_initial[i]); > IndexError: index out of bounds > > I am using Numpy, is it due

Re: [Tutor] HELP: Creating animation from multiple plots

2013-03-27 Thread Peter Otten
Sayan Chatterjee wrote: > for t in range(0,200): > fname = 'file_' + str(t) > > So it will assign fname values file_0, file_1 so on. Dropping the quotes > is giving me > > IOError: [Errno 2] No such file or directory: 'file_0' > > > Indeed the file is not present. In C we write,if we have to

Re: [Tutor] Phyton script for fasta file (seek help)

2013-03-24 Thread Peter Otten
michelle_low wrote: > Hi Peter, > Thanks for your help. You're welcome. In the future, please send your mail to the list, not to an individual poster. That way more people get a chance to read it and you are more likely to get help. > I have followed your advice: > >

Re: [Tutor] Phyton script for fasta file (seek help)

2013-03-24 Thread Peter Otten
michelle_low wrote: > Can someone please help me with the following phyton script? I received Python; write it on the blackboard one hundred times ;) > the error message DeprecationWarning: the sets module is deprecated > from sets import Set. > After googling, I have tried the methods othe

Re: [Tutor] Dictionary get method

2013-03-20 Thread Peter Otten
Phil wrote: > On 20/03/13 15:09, Mitya Sirenef wrote: > > >> >> By the way, you can further simplify it by doing: >> >> def histogram2(s): >> return {c: d.get(c,0)+1 for c in s} >> >> >> That will work in python 3, in python 2 you need: >> >> return dict((c: d.get(c,0)+1) for c in s) >

Re: [Tutor] help with itertools.izip_longest

2013-03-16 Thread Peter Otten
Abhishek Pratap wrote: > I am trying to use itertools.izip_longest to read a large file in > chunks based on the examples I was able to find on the web. However I > am not able to understand the behaviour of the following python code. > (contrived form of example) > > > > for x in itertools.izi

Re: [Tutor] File-Fetcher (cmdline-parser)

2013-03-16 Thread Peter Otten
Christopher Emery wrote: > Hello Peter, > > Thank you this is much appreciated! It is much clear now. Thank you > > PO: Also, if you make it a habit to keep long option and dest in sync > (something you get for free if you only specify the option) you can > deduce the a

<    4   5   6   7   8   9   10   11   12   13   >