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 Is the second result desired? No -- the second should match -- you found a test case I didn't... def test(a,b): for ii in a: if ii

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 thoughts. But one question. Why explicitly convert string

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 next time. if

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 rwob...@hotmail.com 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

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? No -- the second should match -- you found a test case I didn't... def test(a,b): for ii in a: if ii not in b: a=a.replace(ii

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 Peter has replied to this mail

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

Re: [Tutor] Chutes Ladders

2013-12-23 Thread Peter Otten
Keith Winston wrote: On Sun, Dec 22, 2013 at 3:04 PM, tutor-requ...@python.org 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 to streamline, make more readable

Re: [Tutor] Chutes Ladders

2013-12-23 Thread Peter Otten
Keith Winston wrote: On Sun, Dec 22, 2013 at 3:04 PM, tutor-requ...@python.org 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 instructive. But in my haste I

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

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

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 calculation

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 works if the

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 HB2=1.8080

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] 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 expected was

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 1 + int(number)

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, lambda; Sorry, I don't

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 wpr...@gmail.com wrote

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 color to the

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 like to know that the standard English idiom is I took the liberty

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 the input's color

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's color to the corresponding command. ... Are you running the program inside idle

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

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

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] 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 today? )

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

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.listdir(.) for i in f:

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

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, 'name' :

[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 option banner text

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(): word =

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' Usage: test [new_data | text_entry FILE | show_data ] [-hdv] [--db=DATABASE] [--tb

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

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. You have

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 assignment suggests it we should assume its correct. My crystal ball says def

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

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:

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

Re: [Tutor] Python 2 3 and unittest

2013-09-05 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 force

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 in

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

Re: [Tutor] Need help printing a pickled data

2013-06-25 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__(self, data):

Re: [Tutor] mistaken about splitting expressions over lines

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

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] 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 def Increment (

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. It's

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==1:

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

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 stdin, line 1, in module TypeError: 'int' object has no attribute '__getitem__' b = str(a)

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/ITService/SignIn'}

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

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 pyshell#58, line 1, in module 9. khalid=k(3) 10. TypeError: __init__() should

Re: [Tutor] Quick Question on String Compare

2013-06-01 Thread Peter Otten
(number_strings, key=lambda x: (len(x), x)) ['1', '2', '20', '100'] names = [Abe, Peter, Pete, Jim, Jack] sorted(names, key=lambda x: (len(x), x)) ['Abe', 'Jim', 'Zoe', 'Jack', 'Pete', 'Peter'] There is no one sort order that fits all use cases, but Python makes it easy to supply a custom key function

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

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

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() _ Both

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 you

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

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 function of a web

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 the drawn numbers. I'm not sure

Re: [Tutor] Python Idle Crashing

2013-05-17 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 __init__(self):

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\\apple.exe'

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

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

[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 so I'm glad

[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 luck yet. Any ideas? Thanks, Peter R ___ Tutor

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 record

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

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! But I have a question, whenever we want to do

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

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 others

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: -removed the line from

Re: [Tutor] Dictionary get method

2013-03-20 Thread Peter Otten
Phil wrote: On 20/03/13 15:09, Mitya Sirenef wrote: cut 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) Thanks again

Re: [Tutor] Script to generate statements

2013-03-16 Thread Peter Otten
Charles Leviton wrote: I was recently given this task. it's a very IBM mainframe specific task so I'm not sure how to find equivalent terms in another environment. I will just use the mainframe terminology and hopefully y'all can figure out what I mean. Given a list of DBRM members

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 attribute name used

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

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

2013-03-15 Thread Peter Otten
Bod Soutar wrote: mystring = THIS is A string newstring = for item in mystring: if item.isupper(): newstring += item.upper() else: newstring += item.lower() print newstring This does nothing the hard way as newstring and mystring are equal ;) If you

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

2013-03-15 Thread Peter Otten
Christopher Emery wrote: Hello All, OS = Raspbain Wheezy Ubuntu 12.10 (both updated daily) Python Version = 3.2 3.3 Python Understanding = Beginner (very basic - just started) See paste bin for code, has 44 lines, code does not give any errors. http://pastebin.com/2tLHvUym Okay,

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

2013-03-15 Thread Peter Otten
Christopher Emery wrote: Hello Peter, First let me say thanks for your feedback, please see comments / question below, yours starting with PO and mine starting with CE. PO: dest determines the attribute name under which the option is stored. I rarely set it explicitly; instead I provide

Re: [Tutor] Fwd: Which databases allow lists as record fields?

2013-03-14 Thread Peter Otten
DoanVietTrungAtGmail wrote: You don't. You create a second table to hold the list. Then in the second table you include be reference back to the first. I thought about that but thought it seemed a roundabout way. But assuming I do it that way, how to deal with variable-length list? Most

Re: [Tutor] BMI calc

2013-03-13 Thread Peter Otten
Shall, Sydney wrote: I am also a newbie, but I wish to learn, so I offer the following corrections. # Note. I do note know what units you are using. # I would use scientific, metric units. So you need to divide both weight and height by a suitable conversion factors. # Then you will not

Re: [Tutor] BMI calc

2013-03-13 Thread Peter Otten
Shall, Sydney wrote: On 13/03/2013 12:21, Peter Otten wrote: Shall, Sydney wrote: I am also a newbie, but I wish to learn, so I offer the following corrections. # Note. I do note know what units you are using. # I would use scientific, metric units. So you need to divide both weight

Re: [Tutor] implementing rot 13 problems

2013-03-12 Thread Peter Otten
RJ Ewing wrote: Thank you all for the help. I really appreciated the suggestions. Some of the things you pointed out, I originally used, but started changing thing when it wasn't working. I got it to work, but if you could let me know if there is anything I should do to make this code more

Re: [Tutor] Need help with function coding.

2013-03-07 Thread Peter Otten
akuma ukpo wrote: I am defining the function in one .py file and testing the function in another .py file. this is my code for the test: def test_quantity_convert(self): self.assertEqual(gallons_to_cups(0), 16) self.assertEqual(gallons_to_cups(100), 1600) this is

Re: [Tutor] Trying to avoid using eval..

2013-02-23 Thread Peter Otten
Rohit Mediratta wrote: I want to reload my Module after I fix bugs and want to instantiate an object of a class contained in this module. Just a warning about reload(), as your question was already answered: Reloading modules may seem convenient at first, but can lead to strange errors

Re: [Tutor] Class-based generator

2013-02-18 Thread Peter Otten
Michael O'Leary wrote: I wrote some code to create tasks to be run in a queue based system last week. It consisted of a big monolithic function that consisted of two parts: 1) read data from a file and create dictionaries and lists to iterate through 2) iterate through the lists creating a

Re: [Tutor] Strange behaviour of list comprehension

2013-02-13 Thread Peter Otten
Mahadevan, Anand wrote: I'm playing around with list comprehension and in IDLE typed this in. I actually wanted it to return all tuples satisfying the condition where z is the sum of x and y. I kind of got mixed up with the syntax, hence I put a comma in there instead of an if. I'd like

Re: [Tutor] Question on regular expressions

2013-02-12 Thread Peter Otten
Marcin Mleczko wrote: given this kind of string: start SomeArbitraryAmountOfText start AnotherArbitraryAmountOfText end a search string like: rstart.*?end would give me the entire string from the first start to end : start SomeArbitraryAmountOfText start AnotherArbitraryAmountOfText end

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