Re: [Tutor] How to list/process files with identical character strings

2014-06-24 Thread Peter Otten
Peter Otten wrote: > for fileset in days.values(): > if len(fileset) > 1: > # process only the list with one or more files That should have been # process only the lists with two or more files > print(&qu

Re: [Tutor] How to list/process files with identical character strings

2014-06-24 Thread Peter Otten
mark murphy wrote: > Hello Python Tutor Community, > > This is my first post and I am just getting started with Python, so I > apologize in advance for any lack of etiquette. > > I have a directory of several thousand daily satellite images that I need > to process. Approximately 300 of these i

Re: [Tutor] write dictionary to file

2014-06-23 Thread Peter Otten
Ian, take a step back; the first step to solve a problem is to state it clearly. You want to write a dict to a file. (1) What would the dictionary look like? Give concrete example, e. g. {"foo": 42, "bar": 'that\'s not "funny"'} (2) What should the resulting file look like when you open it in a

Re: [Tutor] Pulling items from a dict in a print command

2014-06-18 Thread Peter Otten
Ben Sherman wrote: > Whats a more pythony way to do this? I have a dict with a few dozen > elements, and I want to pull a few out. I've already shortened it with > itemgetter, but it still seems redundant. I feel like I can do something > like I've seen with *kwargs, but I'm not sure. > > I'm

Re: [Tutor] Unicode Encode Error

2014-06-17 Thread Peter Otten
Aaron Misquith wrote: > I'm trying to obtain the questions present in StackOverflow for a > particular tag. > > Whenever I try to run the program i get this *error:* > > Message File Name Line Position > Traceback > C:\Users\Aaron\Desktop\question.py 20 > UnicodeEncodeError: 'ascii' codec c

Re: [Tutor] Problem reading large files in binary mode

2014-06-13 Thread Peter Otten
Mirage Web Studio wrote: > Try reading the file in chunks instead: > > CHUNKSIZE = 2**20 > hash = hashlib.md5() > while True: > chunk = f.read(CHUNKSIZE) > if not chunk: > break > hash.update(chunk) > hashvalue = hash.hexdigest() > &

Re: [Tutor] Fwd: Problem reading large files in binary mode

2014-06-12 Thread Peter Otten
Mirage Web Studio wrote: > I am new to python programming. while trying it out i find that in my > code file io.read is not reading large files particularly over 1 gb. my > code is posted below. i am working on python 3.3 on windows with ntfs > partition and intel corei3 ram 3gb. the execution a

Re: [Tutor] python sockets

2014-06-11 Thread Peter Otten
Alan Gauld wrote: > On 11/06/14 00:08, Jon Engle wrote: >> Ok, so when I run the code it immediately terminates and never 'listens' > > This has nothing to do with your immediate problem but... > >> ***Code*** >> >>#!/usr/bin/python # This is server.py file >> from socket impo

Re: [Tutor] [OT] Long delay until my posts appear

2014-06-11 Thread Peter Otten
Alan Gauld wrote: > On 10/06/14 09:43, Peter Otten wrote: >> I'm posting via gmane. Since last month there is a delay (usually a few >> hours I think) until my posts appear and I seem to be getting a >> >> "Your message to Tutor awaits moderator

Re: [Tutor] python sockets

2014-06-11 Thread Peter Otten
Jon Engle wrote: > Ok, so when I run the code it immediately terminates and never 'listens' > to the ports in the loop. I have verified by running netstat -an | grep > 65530 and the startingPort is not binding. As I've already hinted the easiest way to keep your listening threads alive is to use

[Tutor] [OT] Long delay until my posts appear

2014-06-10 Thread Peter Otten
I'm posting via gmane. Since last month there is a delay (usually a few hours I think) until my posts appear and I seem to be getting a "Your message to Tutor awaits moderator approval, would you like to cancel..." mail every time I post. I'm trying hard to not get annoyed ;) Is there somethin

Re: [Tutor] python sockets

2014-06-10 Thread Peter Otten
Lukas Nemec wrote: > Hi, > > fist - are you really triyng to have open 64 000 ports? ok, i suppose > you have your reasons, but this is not a good idea - you'll block most > applications that use these ports .. > > The problem is with your main function - > you have PORT defined, but it is not g

Re: [Tutor] Fwd: glob and file names

2014-06-06 Thread Peter Otten
Gabriele Brambilla wrote: > 2014-06-05 22:10 GMT-04:00 Peter Romfeld : > > On Friday, June 06, 2014 10:04 AM, Gabriele Brambilla wrote: >>> >>> fiLUMOname = 'Lsum_' + period + '_' + parts[2] + '_' + parts[3] + '_' >>

Re: [Tutor] How to create a dictionary for ount elements

2014-06-04 Thread Peter Otten
jarod...@libero.it wrote: > Dear all thanks for your suggestion!!! > Thanks to your suggestion I create this structure:with open("prova.csv") > as p: > for i in p: > lines =i.rstrip("\n").split("\t") >...: print lines >...: > ['programs ', 'sample', 'gene', 'values'] >

Re: [Tutor] self keyword in recursive function

2014-05-30 Thread Peter Otten
Ritwik Raghav wrote: > I joined the topcoder community tomorrow and tried solving the > PersistentNumber problem: > "Given a number x, we can define p(x) as the product of the digits of x. > We can then form a sequence x, p(x), p(p(x))... The persistence of x is > then defined as the index (0-base

Re: [Tutor] Help on best way to check resence of item inside list

2014-05-27 Thread Peter Otten
jarod...@libero.it wrote: > Dear All > > clubA= ["mary","luke","amyr","marco","franco","lucia", "sally","genevra"," > electra"] > clubB= ["mary","rebecca","jane","jessica","judit","sharon","lucia", > "sally"," Castiel","Sam"] > > I have a list of names that I would to annotate in function of pr

Re: [Tutor] Pygame related question

2014-05-25 Thread Peter Otten
diliup gabadamudalige wrote: > I need to random pick a pygame sprite from a sprite class. > The random module does not allow this to be used on a group. > Is the shortest way to raed in the attributes thatr I need into a list and > then random pick that or is there a shorter way? Sample code is gi

Re: [Tutor] cgi.FieldStorage() causing thread.error: can't allocate lock

2014-05-24 Thread Peter Otten
Alan Gauld wrote: > On 23/05/14 12:57, SABARWAL, SHAL wrote: >> Wondering if anyone came across this error in using form = >> cgi.FieldStorage() >> >> import tempfile >> >> File /tempfile.py", line 83, in _once_lock >> = _allocate_lock() >> >> thread.

Re: [Tutor] Read a matrix with lines in different behavior

2014-05-23 Thread Peter Otten
Felipe Melo wrote: > Hello, > > I want to read the below matrix, identify when the characters in front of > "want = " are equal to "1" and then save in an array and in an output file > the characters above. But I don't know how to identify the second line and > store in a variable: > > alpha=0 b

Re: [Tutor] List of Lists for three Frames

2014-05-17 Thread Peter Otten
ani wrote: > So I thought it would be cool to read a sequence at three different > frames, which I have pasted below. However, I've come across a conundrum: > how to make a list of lists. See, I'd like a final output that displays > data of the type of frame with a + or a - to signify the directio

Re: [Tutor] Alice_in_wonderland Question

2014-05-06 Thread Peter Otten
Jake Blank wrote: > I finally got it. > This was the code: > for k in sorted(word_count, key=lambda x:word_count[x], reverse=True): > print (k, word_count[k]) > > The only question i have now is how to limit the amount of returns the > program runs to the first 15 results. Hint:

Re: [Tutor] PyCountry currency formatting woes

2014-05-06 Thread Peter Otten
Sithembewena Lloyd Dube wrote: > Thanks, i was actually getting the error information to update the post. > Apoligies to waste your time posting here - I could not find an > appropriate PyCountry discussion list and my next best bet seemed to be a > Python users' list. > > For those who care to l

Re: [Tutor] append vs list addition

2014-05-04 Thread Peter Otten
C Smith wrote: > I meant for example: > list1 = [1,2,3] > list2 = [3,4,5] > > newList = list1 + list2 > > versus > > for x in list2: >list1.append(x) > > Which is the preferred way to add elements from one list to another? None of the above unless you need to keep the original list1. Use

Re: [Tutor] Using import

2014-05-04 Thread Peter Otten
event code from being executed on import by adding if __name__ == "__main__": ... # executed only when run as a script Example: $ cat hello.py def hello(name): print("Hello, {}".format(name)) if __name__ == "__main__": hello(&quo

Re: [Tutor] array('c')

2014-05-01 Thread Peter Otten
Ian D wrote: > I have this part of code and am unsure as to the effect of the array('c') > part. Is it creating an array and adding 'c' as its first value? No, the first arg to array.array() is the typecode; data may be passed as the second argument. The typecode "c" creates an array of 8-bit ch

Re: [Tutor] 2s complement binary for negative

2014-05-01 Thread Peter Otten
Ian D wrote: > Can anyone clarify please? > > > Just reading this: > https://wiki.python.org/moin/BitwiseOperators > The section on 2's complement binary for negative integers. > It states: > "Thus the number -5 is treated by bitwise operators as if it were written > "...11101

Re: [Tutor] bit shifting

2014-05-01 Thread Peter Otten
Ian D wrote: > I am trying to follow some code. It is basically a python scratch > interfacing script. > Anyway part of the script has this code. > Searching google for >> greater than signs in code with python has its > issues. > Can anyone clarify this stuff. > I know its about 4 bytes of data.

Re: [Tutor] "Guess My Number" Python 3.4.0 Program partially fixed but now has Logic Errors

2014-04-29 Thread Peter Otten
Stephen Mik wrote: > Stephen Mik-novice programmer-getting desperate Don't despair just yet! As a programmer you will be constantly producing and fixing errors. That is business as usual. What will change is that you will produce trickier bugs as your knowledge level increases... > Dear Sir(s)

Re: [Tutor] Stephen Mik-Almost Brand New to Python 3.4.0-"Guess My Number" program is syntactically correct but will not run as expected

2014-04-28 Thread Peter Otten
Stephen Mik wrote: > My program, Assignment4,does run partially. You can see the results of the > Python Shell attached to this email. I also have included part of my code > for your perusal. > > I must be doing something very wrong. The program is supposed to run a > main loop ,for control of th

Re: [Tutor] Where does logging put its files?

2014-04-24 Thread Peter Otten
Alan Gauld wrote: > I've been playing with the logging module - long overdue! > > I started with the basic tutorial but fell at the first hurdle. > It says to specify a file in the logging.basicConfig() function then > asks you to open the file after logging some events. > > But I can't find the

Re: [Tutor] global list

2014-04-24 Thread Peter Otten
Albert-Jan Roskam wrote: > > > > > > - Original Message - >> From: Steven D'Aprano >> To: tutor@python.org >> Cc: >> Sent: Thursday, April 24, 2014 3:00 AM >> Subject: Re: [Tutor] global list >> > > > >> You only need to define variables as global if you assign to them: >> >> de

Re: [Tutor] equality check difference

2014-04-19 Thread Peter Otten
Peter Otten wrote: > In mathematics there is a property called "transitivity" which basically > says that an operation op is transitive if from > > (a op b) and (a op c) > > follows > > b op c I opened the wikipedia article for the english word, but didn

Re: [Tutor] equality check difference

2014-04-19 Thread Peter Otten
Vipul Sharma wrote: > Hello, > > Suppose we want some block of code to be executed when both '*a'* and > '*b'*are equal to say 5. Then we can write like : > > *if a == 5 and b == 5:* > *# do something* > > But a few days ago, I just involuntarily wrote a similar condition check > as > : >

Re: [Tutor] List issues

2014-04-17 Thread Peter Otten
Wheeler, Gabriel wrote: > Im having trouble completing this function with lists. Im supposed to > create a function that will let me know if there are repeating elements so > I wrote this and am not sure where the error lies. It helps you (and us) a lot if you clearly state the error you are see

Re: [Tutor] questions when define a class

2014-04-15 Thread Peter Otten
Qianyun Guo wrote: > Hi all, I am trying to get a suffix tree from a string. I use three > classes, Node, Edge, SuffixTree. I have two questions when implementing: > > 【1】 > a = Edge(1,2,3,4) > a.length > > 1 > if I remove '@property' in my code, it returns as below: > a = Edg

Re: [Tutor] cdata/aml question..

2014-04-13 Thread Peter Otten
bruce wrote: > The following text contains sample data. I'm simply trying to parse it > using libxml2dom as the lib to extract data. > > As an example, to get the name/desc > > test data > > > d = libxml2dom.parseString(s, html=1) > > p1="//department/name" > p2="//department/desc

Re: [Tutor] improving speed using and recalling C functions

2014-04-12 Thread Peter Otten
Gabriele Brambilla wrote: > Ok guys, when I wrote that email I was excited for the apparent speed > increasing (it was jumping the bottleneck for loop for the reason peter > otten outlined). > Now, instead the changes, the speed is not improved (the code still > running from this m

Re: [Tutor] improving speed using and recalling C functions

2014-04-11 Thread Peter Otten
Gabriele Brambilla wrote: > ok, it seems that the code don't enter in this for loop > > for gammar, MYMAP in zip(gmlis, MYMAPS): > > I don't understand why. You have two variables with similar names, gmlis and gmils: >> gmlis = [] >> gmils=[my_parts[7], my_part

Re: [Tutor] improving speed using and recalling C functions

2014-04-11 Thread Peter Otten
Gabriele Brambilla wrote: > Anyway I would like to try to speed it up using C functions (and maybe > comparing the resuts of the two profile in the end) I can't help you on your chosen path, but let me emphasise that the code you posted looks like it has great potential for speed-up by replacing

Re: [Tutor] How to make comparison work

2014-04-11 Thread Peter Otten
Gregg Martinson wrote: > I have been working through a fairly simple process to teach myself python > and I am running into a problem with a comparison. Can anyone tell me > where I am going wrong? > > #!/usr/bin/env python > > class Team(object): > code = "" > opponents_debated=[] >

Re: [Tutor] Desktop Notifications on Linux

2014-04-10 Thread Peter Otten
Dharmit Shah wrote: > I am trying to create a script that will go through the > /var/log/secure file on a Linux system and provide desktop > notifications for failed login attempts. > > Here is the code - http://pastebin.com/MXP8Yd91 > And here's notification.py - http://pastebin.com/BhsSTP6H >

Re: [Tutor] Question regarding Python loops

2014-04-10 Thread Peter Otten
Conner Crowe wrote: > To whom this may concern: > > I am struggling on two questions: > Problem 2. > Suppose you are given a function leave(minute) which returns the number of > students that leave an exam during its mth minute. Write a function > already_left(t) that returns the number of studen

Re: [Tutor] Delete unwanted rows

2014-04-09 Thread Peter Otten
Alexis Prime wrote: > Hello, > > My question is whether I should write a loop or a function to delete rows. > > I'm using pandas. But you may be able to help me as my question is about > the reasoning behind programming. > > I have a pandas dataframe that looks like this, covering all countries

Re: [Tutor] question about strip() and list comprehension

2014-04-09 Thread Peter Otten
Steven D'Aprano wrote: > On Tue, Apr 08, 2014 at 02:38:13PM -0600, Jared Nielsen wrote: >> Hello, >> Could someone explain why and how this list comprehension with strip() >> works? >> >> f = open('file.txt') >> t = [t for t in f.readlines() if t.strip()] >> f.close() >> print "".join(t) >> >> I

Re: [Tutor] dictionary keys

2014-04-08 Thread Peter Otten
Alex Kleider wrote: > On 2014-04-08 14:34, Peter Otten wrote: > >> That's a change in Python 3 where dict.keys() no longer creates a list, >> but >> instead creates a view on the underlying dict data thus saving time and >> space. In the rare case whe

Re: [Tutor] dictionary keys

2014-04-08 Thread Peter Otten
Alex Kleider wrote: > I've got a fairly large script that uses a dictionary (called 'ipDic') > each > value of which is a dictionary which in turn also has values which are > not > simple types. > Instead of producing a simple list, > """ > ips = ipDic.keys() > print(ips) > """ > yields > """ > di

Re: [Tutor] Storing dictionary value, indexed by key, into a variable

2014-04-05 Thread Peter Otten
John Aten wrote: > I read the article on data driven programming that Danny linked too, and > did some additional looking around. I couldn't find anything directly > using Python, but I got an idea of the concept and went crazy with it. > This may still be off the mark, but I created a complex com

Re: [Tutor] conditional execution

2014-04-04 Thread Peter Otten
spir wrote: > On 04/01/2014 06:24 PM, Zachary Ware wrote: >> Hi Patti, >> >> On Tue, Apr 1, 2014 at 11:07 AM, Patti Scott wrote: >>> I've been cheating: comment out the conditional statement and adjust >>> the indents. But, how do I make my program run with if __name__ == >>> 'main': >>> main()

Re: [Tutor] Storing dictionary value, indexed by key, into a variable

2014-04-03 Thread Peter Otten
John Aten wrote: > I apologize for the omissions, I thought that I had isolated the problem, > but I was way off the mark. The problem was, as suggested by Danny and > Peter, in the function where the dictionary is assigned. I ran the type > function, as Alex advised, and lo an

Re: [Tutor] System output into variable?

2014-04-03 Thread Peter Otten
leam hall wrote: > I've been trying to so a simple "run a command and put the output into a > variable". Using Python 2.4 and 2.6 with no option to move. The go is to > do something like this: > > my_var = "ls -l my_file" > > So far the best I've seen is: > > line = os.popen('ls -l my_file', st

Re: [Tutor] unittest decorators

2014-04-03 Thread Peter Otten
Albert-Jan Roskam wrote: > The unittest module has some really handy decorators: @unittest.skip > and @unittest.skipIf. I use the former for temporary TODO or FIXME things, > but I use the latter for a more permanent thing: > @unittest.skipif(sys.version_info()[0] > 2). Yet, in the test summary yo

Re: [Tutor] Storing dictionary value, indexed by key, into a variable

2014-03-31 Thread Peter Otten
John Aten wrote: > Hey all, > > I am writing a program to drill the user on Latin demonstrative pronouns > and adjectives (DPA). It displays a description, and the user has to enter > the DPA that corresponds to the description. DPA vary for gender, number > and case, and there are 3 separate DPA

Re: [Tutor] ElementTree, iterable container, depth of elements

2014-03-29 Thread Peter Otten
street.swee...@mailworks.org wrote: > I'm trying to sort the order of elements in an xml file, mostly > to make visual inspection/comparison easier. The example xml and > code on http://effbot.org/zone/element-sort.htm get me almost > what I need, but the xml I'm working with has the element I'm

[Tutor] Character counting again, was Re: Tutor Digest, Vol 121, Issue 56

2014-03-24 Thread Peter Otten
Jumana yousef wrote: [Please don't reply to the digest. At the very least change the subject to its original text. Thank you.] > just a reminder of my data: > it cossets of multiple sequences of DNA that I need to count the bases(characters) and calculate the percentage of C+G and calculate the

Re: [Tutor] How to create a sqlite table schema dynamically

2014-03-20 Thread Peter Otten
Alan Gauld wrote: > I confess I'm still not clear on your schema. What should the populated > table(s) look like? It all feels very un-SQL like to me. I'll make a bold guess that he wants to make a pivot table, something that is indeed not supported by sqlite. E. g., start with week | os

Re: [Tutor] apihelper in dive into python

2014-03-19 Thread Peter Otten
robert.gutm...@dlr.de wrote: > Hi guys, > > I've got the following problem: I tried to run the example-program > apihelper.py in chapter IV of "Dive into Python" and got the following > error message: > > Define the builtin 'help'. > This is a wrapper around pydoc.help (with a twist). > > T

Re: [Tutor] Multiple for and if/else statements into a single list comprehension

2014-03-17 Thread Peter Otten
Peter Otten wrote: > [locals()] does not capture > the loop vars of genexps (all pythons) and listcomps (python3). Sorry, I was totally wrong on that one. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options:

Re: [Tutor] Multiple for and if/else statements into a single list comprehension

2014-03-17 Thread Peter Otten
Jignesh Sutar wrote: > Is it possible to get two nested for statements followed by a nested > if/else statement all into a single list comprehension ie. the equivalent > of the below: > > > for i in xrange(1,20): > for j in xrange(1,10): > if j<6: > j=int("8"+str(j)) >

Re: [Tutor] educational

2014-03-11 Thread Peter Otten
MICHAEL BASHAGI wrote: [Please send your posts to the mailing list, not individual posters. Thank you.] > But the PIL doesn't work in my version of Python, i use Python 3.4 If you are still working on this: as Tim hinted there is a fork of PIL called Pillow with installers for Python 3.4. See

Re: [Tutor] help me

2014-03-10 Thread Peter Otten
hind fathallah wrote: > hi I need your help plz with this cods ( I want u to tell wht cod I miss > to stop the while loop whene I get 3 stars) rm = [] I think you are comparing a string and an integer. That gives False even if the values look the same: >>> i = 3 >>> s = "3" >>> print i, s 3 3

Re: [Tutor] educational

2014-03-09 Thread Peter Otten
Ben Finney wrote: > Welcome, Michael! > > MICHAEL BASHAGI writes: > >> when i run those codes i get this error message:- > > When showing an error, please show the entire traceback; it usually > contains information useful for diagnosing the problem. > >> AttributeError: type object 'Image' h

Re: [Tutor] Help with Guess the number script

2014-03-07 Thread Peter Otten
Scott W Dunning wrote: > I am trying to write a script for class for a game called guess the > number. I’m almost done but, I’m having a hard time getting the hints to > print correctly. I’ve tried ‘if’’ ‘elif’ nested, it seems like > everything….I’m posting my code for the hints below, any help

Re: [Tutor] numerical problem

2014-03-04 Thread Peter Otten
Gabriele Brambilla wrote: > for example I read this: > > On Pythons prior to 2.7 and 3.1, once you start experimenting with > floating-point numbers, you're likely to stumble across something that may > look a bit odd at first glance: 3.1415 * 2 # repr: as code (Pythons < 2.7 and 3.1) > 6.28

Re: [Tutor] next element in list

2014-02-26 Thread Peter Otten
rahmad akbar wrote: > hey guys > > i have this file i wish to parse, the file looks something like bellow. > there are only four entry here (AaaI, AacLI, AaeI, AagI). the complete > file contains thousands of entries > > =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= >

Re: [Tutor] subprocess.call list vs. str argument

2014-02-24 Thread Peter Otten
Peter Otten wrote: >> r'-f -F', >> r'-H', '"%s"' % title, > > "title" becomes \"title\", i. e. Python puts in an extra effort to have > the quotes survive the subsequent parsing process of the shell: > >>

Re: [Tutor] subprocess.call list vs. str argument

2014-02-24 Thread Peter Otten
Albert-Jan Roskam wrote: > Hi, > > In the code below, cmd1 and cmd2 are equivalent, as in: " ".join(cmd1) == > cmd2. But the first example returns a code 2, whereas the second runs > successfully. What is the difference? I prefer using a list as it looks a > little cleaner. Btw, shell=True is nee

Re: [Tutor] Class decorator on a derived class not initialising the base classes using super - TypeError

2014-02-24 Thread Peter Otten
Sangeeth Saravanaraj wrote: > On Mon, Feb 24, 2014 at 10:53 PM, Peter Otten <__pete...@web.de> wrote: > >> Sangeeth Saravanaraj wrote: >> >> > I am trying to capture an object initiation and deletion events using >> > the __call__() and __del__() metho

Re: [Tutor] Class decorator on a derived class not initialising the base classes using super - TypeError

2014-02-24 Thread Peter Otten
Sangeeth Saravanaraj wrote: > I am trying to capture an object initiation and deletion events using the > __call__() and __del__() methods with the following approach. Note that there is no guarantee that __dell__ will ever be called. Usually it is better to introduce a weakref with callback. >

Re: [Tutor] os.symlink can't find target

2014-02-24 Thread Peter Otten
Bob Williams wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > My operating system is Linux (openSUSE 13.1). > > I'm trying to create symlinks. The following code: > > if pathList[j][-3:] == "mp3": > linkName1 = pathList[j][0:-3] + "mp3" > linkName2 = destPath + linkName1[len

Re: [Tutor] Function help

2014-02-24 Thread Peter Otten
Scott W Dunning wrote: > > On Feb 23, 2014, at 2:26 AM, Peter Otten <__pete...@web.de> wrote: >> If you want to make rows with more or less stars, or stars in other >> colors you could add parameters: >> >> def star_row(numstars, starcolor): >>fo

Re: [Tutor] Function help

2014-02-23 Thread Peter Otten
Scott W Dunning wrote: > > On Feb 23, 2014, at 1:12 AM, Scott W Dunning wrote: > >> I am VERY new to python (programming too). I had a question regarding >> functions. Is there a way to call a function multiple times without >> recalling it over and over. Meaning is there a way I can call a

Re: [Tutor] constructing semi-arbitrary functions

2014-02-18 Thread Peter Otten
Oscar Benjamin wrote: > On 17 February 2014 20:13, Peter Otten <__pete...@web.de> wrote: >> André Walker-Loud wrote: >>> >>> The 3rd party minimizer utilizes the .func_code.co_varnames and >>> .func_code.co_argcount to determine the name an

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Peter Otten
André Walker-Loud wrote: > Hello python tutors, > > I am utilizing a 3rd party numerical minimization routine. This routine > requires an input function, which takes as arguments, only the variables > with which to solve for. But I don’t want to define all possible input > functions, in a gian

Re: [Tutor] Performing an union of two files containing keywords

2014-02-17 Thread Peter Otten
Aaron Misquith wrote: > I have 2 different text files. > > File1.txt contains: > > file > RAMPython > parser > > File2.txt contains: > > file1234 > program > > I want to perform an union of these both files such that i get an output > file3.txt which contains: > > file > RAMPython > parser12

Re: [Tutor] can I make a while loop true again

2014-02-14 Thread Peter Otten
Ian D wrote: > Anyway thanks. I wondered why array was being mentioned ha ha > So have I got this correct in that when I run a turtle program I am in > fact using this forever loop, so I do not need to use a while True loop at > all really in a turtle gui program? Yes. __

Re: [Tutor] Regular expressions

2014-02-12 Thread Peter Otten
Santosh Kumar wrote: > Hi all, > > I am using ipython. > > 1 ) Defined a string. > > In [88]: print string > foo foobar > > 2) compiled the string to grab the "foo" word. > > In [89]: reg = re.compile("foo",re.IGNORECASE) > > 3) Now i am trying to match . > > In [90]: match = reg.match(stri

Re: [Tutor] can I make a while loop true again

2014-02-11 Thread Peter Otten
Peter Otten wrote: > As a bonus the turtle changes its direction when you hit the left or right > array. I think "arrow" and my fingers decide they'd rather write "array". I'll start proof-reading of these days...

Re: [Tutor] can I make a while loop true again

2014-02-11 Thread Peter Otten
Ian D wrote: > Thanks for the help on the last one. > > Is it possible to restart a while loop? This doesn't work at all (surprise > surprise) > > import turtle as t > > def start(): > global more > more = True > > def stop(): > global more > more = False > > more = True >

Re: [Tutor] Python .decode issue

2014-02-11 Thread Peter Otten
eryksun wrote: > On Tue, Feb 11, 2014 at 3:42 AM, Peter Otten <__pete...@web.de> wrote: >> >> Unfortunately the bytes --> bytes conversion codecs in Python 2 have no >> convenient analog in Python 3 yet. >> >> This will change in Python 3.4

Re: [Tutor] how can I exit a while loop in turtle graphics

2014-02-11 Thread Peter Otten
Ian D wrote: > I am trying to exit a while loop whilst using turtle graphics. > I don't seem to have the logic correct at all. > I have tried a few different things > > These might seem a bit illogical to you guys but to me they make some > sense, sadly > > I just don't really grasp these while

Re: [Tutor] Python .decode issue

2014-02-11 Thread Peter Otten
james campbell wrote: > I have been currently trying to get a small piece of code to work, but > keep getting an error: > > header_bin = header_hex.decode('hex') > AttributeError: 'str' object has no attribute 'decode' > > > The source of this code is from: > https://en.bitcoin.it/wiki/Block_ha

Re: [Tutor] if >= 0

2014-02-10 Thread Peter Otten
rahmad akbar wrote: > hey again guys, i am trying to understand these statements, > > if i do it like this, it will only print the 'print locus' part > > for element in in_file: > if element.find('LOCUS'): > locus += element > elif element.find('ACCESSION'): > accession += element >

Re: [Tutor] second if

2014-02-10 Thread Peter Otten
rahmad akbar wrote: > he guys, i am trying to understand this code: i understand the first if > statement (if line.startswith..) in read_fasta function but couldnt > understand the next one(if index >=...). thanks in advance!! Every time a line starts with a ">" sign the current Fasta instance is

Re: [Tutor] catching the row that raises IntegrityError in sqlite

2014-02-09 Thread Peter Otten
Sivaram Neelakantan wrote: > > I've written this code that seems to work and I'd like to know how to get > the record that causes the abort. Apparently 'executemany' doesn't > support lastrow? And if it doesn't, any suggestions? > > --8<---cut here---start->

Re: [Tutor] learning recursion

2014-02-06 Thread Peter Otten
Denis Heidtmann wrote: > Running python 2.7 on Ubuntu 12.04 > > Code: > def fib2(n): > if n==1: > return 1 > elif n==2: > return 1 > else: > return fib2(n-2) +fib2(n-1) > > The above works: > fib2(7) > 13 fib2(4) > 3 > for i in range(4): > ... print fib2(i) > ... > > The ab

Re: [Tutor] conditionals or comparison or expressions terminology

2014-02-05 Thread Peter Otten
Ian D wrote: Ian, please answer to the list, not me in private. Thank you. > Most of this makes sense except for the c(a<=b) > also > if c(a<=b) > > It is the c(...) syntax that I don't understand. > > I dont recall seeing a statement like this. c is just an arbitrary function, I put in the

Re: [Tutor] Splitting email headers when using imaplib

2014-02-05 Thread Peter Otten
Some Developer wrote: > I'm currently trying to download emails from an IMAP server using > Python. I can download the emails just fine but I'm having an issue when > it comes to splitting the relevant headers. Basically I'm using the > following to fetch the headers of an email message: > > typ,

Re: [Tutor] unsigned int or char equivalent in Python?

2014-02-04 Thread Peter Otten
Alan Gauld wrote: > I'm playing with some bit twiddling code at present and started > to get some unexpected results which i eventually realized > were down to Python ints acting like signed ints in C (but > with a 'flexible' sign bit!) > > This led me to wonder if there is a way to get unsigned

Re: [Tutor] strange errors

2014-02-04 Thread Peter Otten
Gabriele Brambilla wrote: > ok. > the problem is that my "errors" are not always the same and sometimes they > are only differences in the results displayed (with the same starting data > and no random variables used between). Sometimes randomness lurks where you don't expect it. Are there any di

Re: [Tutor] conditionals or comparison or expressions terminology

2014-02-04 Thread Peter Otten
Ian D wrote: > Are: > > <= > == > != > > simple conditionals statements, conditionals, comparison operators, > conditional expressions or what? [comparison] operators: http://docs.python.org/3.3/reference/lexical_analysis.html#operators a <= b # expression (something is evaluated; ideally t

Re: [Tutor] I am teaching my students Python the second semester using www.LearnStreet.com ( http://www.learnstreet.com/ ). I am in need of some help. I am having a problem with the Lists-Set 1 exerci

2014-02-04 Thread Peter Otten
Thomas Maher wrote: > I am teaching my students Python the second semester using > www.LearnStreet.com ( http://www.learnstreet.com/ ). I am in need of some > help. I am having a problem with the Lists-Set 1 exercise 18. The > problem is below. I have put in several codes and the output is 5,

Re: [Tutor] Rsync script hangs after a while

2014-02-04 Thread Peter Otten
Dayo wrote: > I wrote this script (http://bpaste.net/show/175284/) to help me > automate some rsync backups, and whenever I run the script for large > syncs, it just freezes after a while, and then I have to Ctrl+C it. I Maybe you are just lacking patience ;) > can find any clues in both source

Re: [Tutor] JES question concerning syntax

2014-02-04 Thread Peter Otten
Siobhan Wojcik wrote: > Hello, > > I've been having an issue with a program that I'm writing. The program > works until it has to compute something: > > def carPmt(): > cost = requestInteger("How much does the car cost?") > downPmt = requestInteger("If there is a down payment, how much?") >

Re: [Tutor] input python 3.3

2014-02-04 Thread Peter Otten
Ian D wrote: > Hello > > I used to use 2.7 and the input was pretty when inputting a numeric value, > it would just get cast to an int. > > Seems that 3.3 I have to cast each input so : > float(num1 = input("Enter a number") You mean num1 = float(input("Enter a number")) > Is this just t

Re: [Tutor] strange errors

2014-02-03 Thread Peter Otten
Gabriele Brambilla wrote: > No, i'm not using lowlevel stuff...which part of the script do you want > to see? The part that remains when you throw out everything that has no effect on the "strange errors" ;) For example if you have a routine def load_data(filename): ... # do complex proc

Re: [Tutor] strange errors

2014-02-03 Thread Peter Otten
Gabriele Brambilla wrote: > an example of errors that I obtain is: I build a matrix (SciPy array) > using the same data. > I search for the maximum and the minimum with the given function and I > insert the two values in a tuple that I print. > sometimes it print to me this: (0.0, 3.19266766501244

Re: [Tutor] Traversing lists or getting the element you want.

2014-02-03 Thread Peter Otten
Kipton Moravec wrote: > I am new to Python, and I do not know how to traverse lists like I > traverse arrays in C. This is my first program other than "Hello World". > I have a Raspberry Pi and they say Python is the language of choice for > that little machine. So I am going to try to learn it. >

Re: [Tutor] sorting and writing to data file

2014-02-02 Thread Peter Otten
Alan Gauld wrote: > You need a loop such as > > for item in lab3int: >intFile.write( str(item) ) You also need to separate the values, with a space, a newline or whatever. So: for item in lab3int: intFile.write(str(item)) intFile.write("\n") This can be simplified to for item in

Re: [Tutor] how do (or do I) do a list of variable names?

2014-02-02 Thread Peter Otten
rick wrote: > Hello Everyone, > > I think my approach is all wrong, but here goes. > > var1 = []; var2 = []; var3 = []; . . . ~50 lists > > > each variable would be a list of two digit integers, or two digit > integers stored as strings (I don't need to do any math, I just need to > know whi

Re: [Tutor] Split Method

2014-01-30 Thread Peter Otten
Rafael Knuth wrote: > Hey there, > > I am having some issues with splitting strings. > I already know how to split strings that are separated through empty > spaces: > > def SplitMyStrings(): > Colors = "red blue green white black".split() > return (Colors) > > print(SplitMyStrings()) >

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