Re: [Tutor] Pmw/Tkinter question

2016-03-12 Thread Peter Otten
Albert-Jan Roskam wrote: > Hello, > > Below is a slightly modified example about Pmw/Tkinter from > http://pmw.sourceforge.net/doc/howtouse.html. I changed the geometry > manager from 'pack' to 'grid', because I use that in all other parts of my > program. The problem is, 'broccoli' won't display

Re: [Tutor] Recommendations for best tool to write/run Python

2016-03-03 Thread Peter Otten
Lisa Hasler Waters wrote: > I am new to Python, as are my middle school students. We are using Python > 3.5.1 IDLE to write and run our (simple) code. However, this tool does not > seem to be the best way to write longer code or to be able to re-edit code > that has been saved/closed/reopened. Hi

Re: [Tutor] Convert structured 1D array to 2D array

2016-02-27 Thread Peter Otten
Ek Esawi wrote: > The result i am looking for is a 2D array (matrix) instead of 1D array > of tuples. That's when i read a file using genfromtxt, it generated a 1D > array of n tuples (like the example shown below); each tuple has one row > from the original file. The file contains multiple data t

Re: [Tutor] Convert structured 1D array to 2D array

2016-02-27 Thread Peter Otten
Peter Otten wrote: > Or try > > b = numpy.array(a, dtype=(object, object)) That won't work, I accidentally tested it on an already converted array :( ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription

Re: [Tutor] Convert structured 1D array to 2D array

2016-02-27 Thread Peter Otten
Ek Esawi wrote: > Thanks for the input. I tried your idea but i did not work; l got 1D array > of tuples; the same as the original array. I think b/c genfromtxt creates > an array and so it's already an array object-if i understand it correctly. > Your idea works well for a list which i tested but

Re: [Tutor] Convert structured 1D array to 2D array

2016-02-26 Thread Peter Otten
Ek Esawi wrote: > I used genfromtxt to read a file with multiple data types. The result was > a 1D array of tuples; for example > > [(1, 2, 3), (‘a’, b’, ’c’), (‘12/12/2009’, ’2/4/2014’, ‘3/4/200)’] > > > > I am trying to convert this structured array to a 2D array. Is this > possible where th

Re: [Tutor] Finding line number by offset value.

2016-02-22 Thread Peter Otten
Steven D'Aprano wrote: > On Mon, Feb 22, 2016 at 01:41:42AM +, Alan Gauld wrote: >> On 21/02/16 19:32, Cody West wrote: > >> > I'm trying to take 48L, which I believe is the character number, and >> > get the line number from that. The documentation isn't explicit, but """ with open('/foo/b

Re: [Tutor] a beginning question

2016-02-20 Thread Peter Otten
Paul Z wrote: > Hi, > > I writed some codes as the UDP messages: > > import socket > import random > from array import * > > port = 8088 > host = "localhost" > > s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) > > num = array('f') > x = 0 > while x < 6: > num.append(random.random()) > x +

Re: [Tutor] Hello! Questions

2016-02-19 Thread Peter Otten
Marco Soldavini wrote: Random remarks about your code: > #While loop - scanning and storing OPC values at scan rate > while (abort == 0): The loop continues to work if you change it to while True: > # ESC pressed? > if msvcrt.kbhit() and ord(msvcrt.getch()) == 27: > abort = 1

Re: [Tutor] really basic - finding multiline chunk within larger chunk

2016-02-16 Thread Peter Otten
bruce wrote: > I've got a test, where I have a chunk of text "a" and a subset of text > "s2a". the subset is multiline. > > For some reason, can't seem to return true on the find. I've pasted in > http://fpaste.org/323521/, but the following is an example as well. > (not sure if the psuedo code l

Re: [Tutor] tk Radiobutton example

2016-02-15 Thread Peter Otten
paul.hermeneu...@gmail.com wrote: > +I am working through "Python GUI Programming Cookbook" by Burkhard Meier. > https://www.packtpub.com/application-development/python-gui-programming-cookbook > > On page 20, the variable curRad is set to a string then to a > Radiobutton. What is the purpose of

Re: [Tutor] declare a variable inside a class

2016-02-11 Thread Peter Otten
richard kappler wrote: > Thanks for the reply Martin, and in this instance I cannot post the actual > code (company rules). What I can do is say that with the xslt variable > defined within the formatter method, everything works, but when I pull it > out and put it in the upper level of the class,

Re: [Tutor] Need help with two similar test cases that I have written. One works and the other fails

2016-02-07 Thread Peter Otten
Anubhav Yadav wrote: >> Hi Anubhav, >> >> Ah! The assert functions are meant to be used as statements, not as >> composable expressions. If you're familiar with the idea of side >> effects, then you need to understand that you should be calling the >> assert functions just for their side effects

Re: [Tutor] script follows a file into zip?

2016-02-05 Thread Peter Otten
richard kappler wrote: > I have a script that checks a file and if there are new additions to the > file, parses and sends the new additions. This log rolls over and zips at > midnight creating a new log of the same name. The problem is, when the > file rolls over, the new file seems to follow the

Re: [Tutor] recursion

2016-02-05 Thread Peter Otten
Ben Finney wrote: > Alan Gauld writes: > >> On 05/02/16 02:03, noopy via Tutor wrote: >> >> > def permutations(items): >> > n = len(items) >> > if n==0: yield [] >> > else: >> >> I assume this bit is clear enough? > > I think it would be clearer without the needless opaque name ‘

Re: [Tutor] 2016-02-03 Filter STRINGS from urllib and Pass as VARAIBLE within PYTHON script

2016-02-03 Thread Peter Otten
knnleow GOOGLE wrote: > advice on how to filter VARIABLES from output below. > > 01. need to strip out >BEGIN_STRINGS b'{ and >END_STRINGS }\n' In b'{...}' the b prefix indicates that you are dealing with a byte string. You have to decode it and then you can use the json module

Re: [Tutor] How to write tests for main() function that does not return anything

2016-02-03 Thread Peter Otten
Pedro Miguel wrote: > Hi guys, I'm trying to test the code in the main() but I'm a bit unsure > how to go about it since I'm not passing any arguments or even returning > anything other then logging. For the purposes of the example I've > shortened the tree statements in the function.. Can anyone

[Tutor] [OT] Calculus comic, was Re: Fwd: Finding the max value from a dictionary that does not exceed a variable's value.

2016-02-01 Thread Peter Otten
Steven D'Aprano wrote: > On Mon, Feb 01, 2016 at 12:00:47PM -0800, Danny Yoo wrote: >> Here's a response I sent to Srinivas yesterday to further explain why >> a balanced binary tree is probably overkill for the "largest >> denomination" selection problem. (I didn't realize that I had not >> sent

Re: [Tutor] Change datatype for specific columns in an 2D array & computing the mean

2016-01-25 Thread Peter Otten
Oscar Benjamin wrote: > On 24 January 2016 at 17:24, Peter Otten <__pete...@web.de> wrote: >> >> I'm an amateur with numpy, and unfortunately my favourite search engine >> didn't come up with a numpy-specific way to group rows in a 2D array. > > What

Re: [Tutor] Change datatype for specific columns in an 2D array & computing the mean

2016-01-24 Thread Peter Otten
Ek Esawi wrote: > Thanks for the input. Columns 2 and 3 are strings and i assume that they > don't need to be converted. Because all i need is to compute the mean for > data on column 4 based on each variable in column 1 and each in column 2.. I'm an amateur with numpy, and unfortunately my favou

Re: [Tutor] Change datatype for specific columns in an 2D array & computing the mean

2016-01-24 Thread Peter Otten
Ek Esawi wrote: > Hi All--- > > > > Sorry for posting again, but I have a problem that I tried several > different ways to solve w/o success. I approached the problem from one > angle and asked about it here; I got some good input using pandas, and > structured array, but I am new to python and

Re: [Tutor] mock

2016-01-23 Thread Peter Otten
Alex Kleider wrote: > Some weeks (perhaps months) ago, I posted a question about testing > and got many responses but had trouble grasping the concepts > so I settled on the suggestion that I thought would be the easiest > to implement (using unittest.mock.) Here it is- > >

Re: [Tutor] Extract several arrays from a large 2D array

2016-01-22 Thread Peter Otten
Ek Esawi wrote: > Thank you all for your help. I am a decent programmer in another language > but new to Python and I have some issues with a project I am working on. > Some suggested using pandas but I am barley starting on Numpy. The > suggestions were very helpful, however, I decided to replace

Re: [Tutor] Extract several arrays from a large 2D array

2016-01-21 Thread Peter Otten
Alan Gauld wrote: > So in pseudo code: > > data = {} > for row in myArray: > data.get((row[0],row[1]),[]).append row[3] Replace get() with setdefault() to go from pseudo to Python code. ___ Tutor maillist - Tutor@python.org To unsubscribe or ch

Re: [Tutor] Extract several arrays from a large 2D array

2016-01-21 Thread Peter Otten
Ek Esawi wrote: > Hi All-- > I have a 2D array (2000, 4); an example is given abelow. On the 1st > column I have 15 variables, on the 2nd 4 variables. Ignore column 3 for > now. I want a code that generate 4 arrays for each variable on the 1st > column; each array contains all the values from co

Re: [Tutor] Simultaneous read and write on file

2016-01-19 Thread Peter Otten
Anshu Kumar wrote: > Hello All, > > So much Thanks for your response. > > Here is my actual scenario. I have a csv file and it would already be > present. I need to read and remove some rows based on some logic. I have > written earlier two separate file opens which I think was nice and clean. >

Re: [Tutor] Beautiful Soup

2016-01-19 Thread Peter Otten
Crusier wrote: > Hi Python Tutors, > > I am currently able to strip down to the string I want. However, I > have problems with the JSON script and I am not sure how to slice it > into a dictionary. > > import urllib > import json > import requests > > from bs4 import BeautifulSoup > > > url =

Re: [Tutor] pandas data frame

2016-01-18 Thread Peter Otten
Bachir Bachir via Tutor wrote: > Hi Peter Thank you much for your help its very appreciated ,bellow is an > example of what i need. The main dataframe ( need to be separated into > separate dataframes ). The desired dataframes output correctly as i need > it to be,Thanks much Main

Re: [Tutor] Simultaneous read and write on file

2016-01-18 Thread Peter Otten
Anshu Kumar wrote: > Hello Everyone, > > I try below code in python 2.7.10 to first create and write into a file > and > then read and write that file but what i get is just a file with new > content. > > with open('test.txt', 'wb+') as f: > ... f.write('this is test file.') > ...

Re: [Tutor] pandas data frame

2016-01-18 Thread Peter Otten
Bachir Bachir wrote: [Bachir, please send your mails to the list, not to me. That way you increase the likelihood to get a good answer] >> On Sunday, January 17, 2016 4:20 PM, Peter Otten <__pete...@web.de> >> wrote: >> Bachir Bachir via Tutor wrote: >>>

Re: [Tutor] Source of MySQL Command Interpreter

2016-01-17 Thread Peter Otten
Ricardo Martínez wrote: > Hi, i wrote a small APP to execute MySQL commands and retrieve to a > Treeview > > http://pastebin.com/v2C8kAu1 > > Share your comments and upgrades. Well, you have an application that works -- that's good. Do you have specific questions in mind? Then don't hesitate t

Re: [Tutor] pandas data frame

2016-01-17 Thread Peter Otten
Bachir Bachir via Tutor wrote: > Hello EverybodyI need to sort a dataframe according to a specific column > the create new dataframes according to the sorted columns each new created > dataframe should contain the list(set('the sorted element)any help please > , i am new in python and pandas thank

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-17 Thread Peter Otten
boB Stepp wrote: >> The hard part is to remember to test whenever a negative index is >> calculated. > > I am assuming that this is relevant to what just came before, the use > of this "or None" check. Is this correct? No, I mean that you always should test your code against the corner cases.

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-17 Thread Peter Otten
Steven D'Aprano wrote: >> Slightly related is a problem that comes up in practice; you cannot >> specify "including the last item" with negative indices: > > But you can do so by leaving the end index blank: That's why the problem typically comes up when the stop index is a variable. __

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-16 Thread Peter Otten
Steven D'Aprano wrote: > But slices are slightly different. When you provide two indexes in a > slice, they mark the gaps BETWEEN items: The other explanation that Python uses half-open intervals works for me. > Now, what happens with *negative* indexes? > > mylist = [ 100, 200, 300, 400, 500

Re: [Tutor] Help!

2016-01-15 Thread Peter Otten
Chelsea G wrote: > What I am having issues with is the def txt_output that is where I am > trying to take the .csv off and add the .txt but keep the filename the > same. For example, having a filename "weekly_20160102.csv" and then create > a txt filename with "weekly_20160102.txt" and have all th

Re: [Tutor] str.strip strange result...?

2016-01-15 Thread Peter Otten
Jignesh Sutar wrote: > #python2.7 > s="V01_1" s.strip("_1") > 'V0' > > > Wouldn't you expect the result to be "V01" ? str.strip() doesn't strip off a suffix or prefix; its first argument is interpreted as a character set, i. e. as long as s ends/starts with any of the characters "_

Re: [Tutor] Question about the memory manager

2016-01-11 Thread Peter Otten
Oscar Benjamin wrote: > On 11 January 2016 at 12:15, Alan Gauld wrote: >> >> But I think that it definitely is heavily OS dependent. >> It should work in most *nix environments the first time >> you call the function. But on second call I'd expect >> all bets to be off. And in most real-time OS's

Re: [Tutor] (no subject)

2016-01-10 Thread Peter Otten
Lawrence Lorenzo wrote: > import randomimport timeimport math > #the player and NPC class.class char(object): #character attributesdef > #__init__(self, name, health, attack, rng, magic, speed):self.name > #= nameself.health = healthself.attack = attack > #self.s

Re: [Tutor] Question about the memory manager

2016-01-10 Thread Peter Otten
Albert-Jan Roskam wrote: > Hi, > > I just found a neat trick to free up an emergency stash of memory in a > funtion that overrides sys.excepthook. The rationale is that all > exceptions, including MemoryErrors will be logged. The code is below. My > question: is that memory *guaranteed* to be fre

[Tutor] Printing a list without square brackets, was Re: Hi Tutor

2016-01-09 Thread Peter Otten
yehudak . wrote: > I wrote this short program for my grandson: Nothing against a little help here and there, but solving a problem can be fun, and you are taking away some of that fun. Does your grandson speak English? You might encourage him to post here himself. We bite, but only grandpas ;

Re: [Tutor] Not sure why the code is giving weird result?

2016-01-09 Thread Peter Otten
Whom Isac wrote: > Hi, today I tried to help with one of the request in Python tutor about > trailing zeros -6days old. > I don't know why my code is incrementing in number. > Here is the code: > > def factorial(): > print("Here you will put your factorial") > factVar=int(input("Please in

Re: [Tutor] help with existing code

2016-01-07 Thread Peter Otten
Brianna McGee wrote: > I am a new to programming and have started out with modifying existing > code to suit my purposes in my Developmental Psychology lab. The script > worked fine previous to my fiddling with it, but now that I am trying to > modify the x and y locations based upon a text file w

Re: [Tutor] Teaching Python

2016-01-06 Thread Peter Otten
yehudak . wrote: > My grandson Guy (8th grader) is learning Python at school. That's what > made me teach myself Python programming as well. > Yesterday he asked my help in his homework: > > Write a FOR-loop that prints all numbers up to 100 > > Thank you, the gods of Ctrl+C Did you mean to

Re: [Tutor] method, type?

2016-01-06 Thread Peter Otten
Alex Kleider wrote: > #!/usr/bin/env python3 > # OS: Ubuntu 10.4LTS > > # My code: > > class JournalLineItem(object): > """ > """ > > def __init__(self, account, debit_or_credit, amount): > self.account = account > self.debit_or_credit = debit_or_credit >

Re: [Tutor] lists+sort

2016-01-05 Thread Peter Otten
Pooja Bhalode wrote: > Hi, I wanted to check if this program can be used to merge the lists > together and sort them. This seems to work, but i wanted to check if there > are drawbacks in writing it in this manner. When you start out lists are the natural datatype to use, but as you get more exp

Re: [Tutor] To FORMAT or not to

2016-01-03 Thread Peter Otten
yehudak . wrote: > Hi there, > In a program I wrote the following line (Python 3.5): > > print("You've visited", island, '&', new + ".") > > A programmer told me that it's a bad habit, and I should have used > instead: > > print("You've visited {0} {1} {2}{3}".format(island, "&", new, ".")) >

Re: [Tutor] the products of an element of a list

2015-12-26 Thread Peter Otten
Tahir Hafiz wrote: > Finally getting round to doing some more python. > Stuck on a little online exercise: > "Define a function prod(L) which returns the product of the elements in a > list L." > > Let's say L = [1, 2, 3, 4] > > I have done this so far but it's not quite working: > > > > def

Re: [Tutor] Optimize the code - removing the multiple IF conditions

2015-12-21 Thread Peter Otten
Sunil Tech wrote: > Hi, > > I Have a code.. > > > class OptIf(object): > """docstring for OptIf""" > > def opt_me(self, ext): > if ext == 'CM': > rec = self.call_cm(cm, ad) > if ext == 'MM': > rec = self.call_mm(mm, ax) > if ext == 'DM':

[Tutor] Fwd: Kivy Install

2015-12-17 Thread peter mcfarlane
Hi, I don't know if this is the correct forum, I am new to Python and trying to install Kivy. I keep getting the following error message. Can you help? thanks, pete pip install --user Kivy Collecting Kivy Using cached Kivy-1.9.0.tar.gz Requirement already satisfied (use --upgrade to

Re: [Tutor] Understanding a linear runtime implementation of anagram detection

2015-12-10 Thread Peter Otten
Spyros Charonis wrote: > Dear All, > > I am learning about analysis of algorithms (python 2.7.6). I am reading a > book (Problem solving with Algorithms and Data Structures) where Python is > the language used for implementations. The author introduces algorithm > analysis in a clear and understa

Re: [Tutor] Read lines opening with a particular set of characters from a file

2015-11-28 Thread Peter Otten
Br. Sayan wrote: > I am doing the following : > > with open('Manwal.txt') as infile, open('Manwal_req.txt','w') as outfile: > for line in infile: > if line.startswith(('R')): > outfile.write(line) > > It is executing without error but returns a blank file. Where is the >

Re: [Tutor] a class that may not be instantiated

2015-11-24 Thread Peter Otten
Albert-Jan Roskam wrote: > I have two classes with a number of methods that are the same, so I want to define a super class that holds these methods. But the super class (below called _Generic) should not be instantiated, because it serves no purpose other than the DRY principle. I raise a NotI

Re: [Tutor] How to kill a thread

2015-11-24 Thread Peter Otten
CMG Thrissur wrote: > Thank you all. i have pasted the code on pastebin. > > http://pastebin.com/embed_iframe.php?i=kHAUJQC2 > > My one main question in the code is that there are times when my thread > using pythonwhois hangs up the process by statying active very long > time. can i hope for

Re: [Tutor] Squaring every digit in number

2015-11-21 Thread Peter Otten
Aadesh Shrestha wrote: > I am currently taking challenges on codewars. > Problem: Square Every Digit > > is there a better solution than this which requires less code? > > def square_digits(num): > arr = [] > list = [] > while(num !=0): > temp = num%10 > num = num /1

Re: [Tutor] Dictionary on data

2015-11-20 Thread Peter Otten
jarod_v6--- via Tutor wrote: > Dear All! > I have this elements > > In [445]: pt = line.split("\t")[9] > > In [446]: pt > Out[446]: 'gene_id "ENSG0223972"; gene_version "5"; transcript_id > "ENST0456328"; transcript_version "2"; exon_number "1"; gene_name > "DDX11L1"; gene_source "havan

Re: [Tutor] unittest not working

2015-11-19 Thread Peter Otten
Mike wrote: > I'm trying to unit test a self-built regular expression processor for an > assignment. I'm trying to set up unit tests for the package, but it's not > executing them. This is my first time trying to use the unittest module, > so I'm sure I'm missing something, I'm just not sure what

Re: [Tutor] Strange error

2015-11-19 Thread Peter Otten
jarod_v6--- via Tutor wrote: > HI!! > This is my list: > > In [378]: type(Span) > Out[378]: list > > In [379]: Span > Out[379]: > [['M02898:39:0-AH4BK:1:2107:17412:10850', > 'M02898:39:0-AH4BK:1:2117:15242:18766', > 'M02898:39:0-AH4BK:1:1112:21747:21214', > 'M02898:

Re: [Tutor] Help - International School in Spain

2015-11-17 Thread Peter Otten
Peter Otten wrote: >> print("Mashed ",veg," on the ceiling.") An unrelated note: Python automatically adds spaces between the printed values, so the output of print("Mashed", veg, "on the ceiling.") will look better. __

Re: [Tutor] Help - International School in Spain

2015-11-17 Thread Peter Otten
caroline metcalf wrote: > Hi there > > I am having an issue. This code normally works fine > > Code: > veg="carrots" > print("Mashed ",veg," on the ceiling.") > print("Green beans on the floor.") > print("Stewed tomatoes in the corner.") > print("Squash upon the door.") > > But, I am getting t

Re: [Tutor] Unable to retreive the stock code

2015-11-16 Thread Peter Otten
Crusier wrote: > Dear All, > > I am currently trying to download the stock code. I am using Python > 3.4 and the code is as follows: > > from bs4 import BeautifulSoup > import requests > import re > > url = > 'https://www.hkex.com.hk/eng/market/sec_tradinfo/stockcode/eisdeqty.htm' > > def web_

Re: [Tutor] question about descriptors

2015-11-13 Thread Peter Otten
Albert-Jan Roskam wrote: >> __getattr__() is only invoked as a fallback when the normal attribute >> lookup fails: > > > Aha.. and "normal attributes" live in self.__dict__? I meant "normal (attribute lookup)" rather than "(normal attribute) lookup". __getattr__() works the same (I think) when

Re: [Tutor] question about descriptors

2015-11-11 Thread Peter Otten
Albert-Jan Roskam wrote: >> From: st...@pearwood.info >> Fortunately, Python has an mechanism for solving this problem: >> the `__getattr__` method and friends. >> >> >> class ColumnView(object): >> _data = {'a': [1, 2, 3, 4, 5, 6], >> 'b': [1, 2, 4, 8, 16, 32], >>

Re: [Tutor] question about descriptors

2015-11-11 Thread Peter Otten
Albert-Jan Roskam wrote: >> class ReadColumn(object): >> def __init__(self, index): >> self._index = index >> def __get__(self, obj, type=None): >> return obj._row[self._index] >> def __set__(self, obj, value): >> raise AttributeError("oops") > > This appears t

Re: [Tutor] question about descriptors

2015-11-07 Thread Peter Otten
Albert-Jan Roskam wrote: > > > p, li { white-space: pre-wrap; } > > Hi, > First, before I forget, emails from hotmail/yahoo etc appear to end up in > the spam folder these days, so apologies in advance if I do not appear to > follow up to your replies. Ok, now to my question. I want to create a

Re: [Tutor] command line list arguments

2015-11-07 Thread Peter Otten
Garry Willgoose wrote: > I want to input a python list as a command line argument as for example > > python weathering-sens.py -daughter ['p0-50-50','p0-0-0-100’] > > but what I get from sys.argv is [p0-50-50,p0-0-0-100] without the string > delimiters on the list elements. I’m probably missing

Re: [Tutor] parsing xml as lines

2015-11-04 Thread Peter Otten
richard kappler wrote: > I have an xml file that get's written to as events occur. Each event > writes a new 'line' of xml to the file, in a specific format, eg: > sometthing like this: > > http://www.w3.org/2001/XMLSchema-instance"; > xsi:noNamespaceSchemaLocation="Logging.xsd" version="1.0"> h

Re: [Tutor] How to parse large files

2015-11-01 Thread Peter Otten
Alan Gauld wrote: > On 01/11/15 20:33, jarod_v6--- via Tutor wrote: >> Thanks!! >> I use python2.7 Can Also use in that version? >> I don't understand why use partition and not split(). what is the reason >> for that? > > I'm confused? Where did partition v split enter into things? > Am I missin

Re: [Tutor] How to parse large files

2015-11-01 Thread Peter Otten
jarod_v6--- via Tutor wrote: > Thanks!! > I use python2.7 Can Also use in that version? Yes. > I don't understand why use partition and not split(). what is the reason > for that? If there is exactly one "\t" in the line key, value = line.split("\t") and key, _tab, value = line.partition("\

Re: [Tutor] How to parse large files

2015-11-01 Thread Peter Otten
Danny Yoo wrote: >> AttributeErrorTraceback (most recent call >> last) in () >> > 1 with shelve.open("diz5") as db: >> 2 with open("tmp1.txt") as instream: >> 3 for line in instream: >> 4 assert line.count("\t") == 1 >>

Re: [Tutor] Messy - Very Messy string manipulation.

2015-10-28 Thread Peter Otten
Alan Gauld wrote: > On 28/10/15 16:37, Peter Otten wrote: > >>>>> 'The cow moos louder than the frog'.translate(str.maketrans("", "", >> "aeiouAEIOU")) >> 'Th cw ms ldr thn th frg' > > Even easier, forget

Re: [Tutor] Messy - Very Messy string manipulation.

2015-10-28 Thread Peter Otten
Alex Kleider wrote: > On 2015-10-28 09:37, Peter Otten wrote: >> Vusa Moyo wrote: >> >>> I've written a script to remove vowels from a string/sentence. >>> >>> the while loop I'm using below is to take care of duplicate vowels >>>

Re: [Tutor] Demystification of Lambda Functions

2015-10-28 Thread Peter Otten
Steven D'Aprano wrote: > Sometimes callbacks are particularly short and simple. Suppose you are > programming a calculator, and you have ten buttons 0...9 which all do > precisely the same thing: they add their own name to the calculator > display: > > > for num in range(0, 10): > btn = B

Re: [Tutor] Messy - Very Messy string manipulation.

2015-10-28 Thread Peter Otten
Vusa Moyo wrote: > I've written a script to remove vowels from a string/sentence. > > the while loop I'm using below is to take care of duplicate vowels found > in a sentence, ie > > anti_vowel('The cow moos louder than the frog') > > It works, but obviously its messy and n00by. Any suggestions

Re: [Tutor] How do I (idiomatically) determine when I'm looking at the last entry in a list?

2015-10-28 Thread Peter Otten
Flynn, Stephen (L & P - IT) wrote: > Afternoon, > > Python 3. > > I'm iterating through a list and I'd like to know when I'm at > the end of the said list, so I can do something different. For example > > list_of_things = ['some', 'special', 'things'] > for each_entry in list_of_things: > print

Re: [Tutor] How to parse large files

2015-10-28 Thread Peter Otten
Danny Yoo wrote: > There are several out there; one that comes standard in Python 3 is > the "dbm" module: > > https://docs.python.org/3.5/library/dbm.html > > Instead of doing: > > diz5 = {} > ... > > we'd do something like this: > > with diz5 = dbm.open('diz5, 'c'): > ... > > And otherwise

Re: [Tutor] GET function not executed

2015-10-18 Thread Peter Otten
Peter Otten wrote: > The use of {...} makes this a set literal, and the order of the items in a > set is undefined. To prevent a class of attacks on web applications it may > even change between invocations: Sorry, I forgot to include the source of setdemo.py. It contains just one lin

Re: [Tutor] GET function not executed

2015-10-18 Thread Peter Otten
Rahul Pathak wrote: > Hi, > > I started with python web module and i have no experience with web. > > I used the example which is on the web.py site - > > -- > import web > > urls = { > '/', 'index' > } > > class index: > def GET(self): >

Re: [Tutor] Changes to dbm module/file format

2015-10-16 Thread Peter Otten
Alan Gauld wrote: > Has anyone noticed a change to the DBM file format or is it an OS > specific thing? Last time I used dbm it was on a Windoze box with > Python 3.3 and it generated sets of 3 files for each 'database' > created. (I think this is what it did under v2 as well?) > > I just used it

Re: [Tutor] File operation query

2015-10-15 Thread Peter Otten
Reuben wrote: > I need some clarification for below code. In line 2 of below code snippet, > I have provided read and write permission. Assuming I have provided some > string input as requested in line 1 - when I try to open "check.txt" file > after running the script, it is always empty - it does

Re: [Tutor] how to unittest cli input

2015-10-15 Thread Peter Otten
Alex Kleider wrote: > On 2015-10-14 12:27, Peter Otten wrote: >> Alex Kleider wrote: >> >>> On 2015-10-13 14:44, Alex Kleider wrote: >>>> On 2015-10-13 12:11, Danny Yoo wrote: >>>> >>>> >>>>> #

Re: [Tutor] how to unittest cli input

2015-10-14 Thread Peter Otten
Alex Kleider wrote: > On 2015-10-13 14:44, Alex Kleider wrote: >> On 2015-10-13 12:11, Danny Yoo wrote: >> >> >>> ## >>> def make_ask(f, l, p): >>> d = {'Enter your first name: ' : f, >>>'Enter your last name: ' : l, >>>'Your mobile phone #: ' : p}

Re: [Tutor] Guidance on using custom exceptions please

2015-10-13 Thread Peter Otten
David Aldrich wrote: > Consider a 'send' method that sends a message to another system via a > socket. This method will wait for a response before returning. There are > two possible error conditions: > > > 1) Timeout - i.e. no response received > > 2) Illegal response received > >

Re: [Tutor] how to unittest cli input

2015-10-11 Thread Peter Otten
Alex Kleider wrote: > It'll take more studying on my part before I'll be able to implement > Ben's suggestion. I find Ben's example instructive, but when you're just starting you might prefer a simpler approach: import unittest from unittest import mock import collect class TestCollectData(u

Re: [Tutor] How to read all integers from a binary file?

2015-10-09 Thread Peter Otten
David Aldrich wrote: > Hi > > I have a binary file of 32-bit unsigned integers. I want to read all those > integers into a list. > > I have: > > ulData = [] > with open(ulBinFileName, "rb") as inf: > ulData.append(struct.unpack('i', inf.read(4))) > > This obviously reads only o

[Tutor] How to write a teller machine simulation, was Re: Python 3.5 Question

2015-10-09 Thread Peter Otten
Sasuke Uchiha wrote: > Hi, I would like to know how to create a code similar to the result below. > I want to input a number like 1000, and for it to give me the maximum > output with the least amount of bills (such as 100s) > >- > >The bill amounts you have are 100s, 50s, 20s, 10s, 5s,

Re: [Tutor] Cumulative distribution function

2015-10-01 Thread Peter Otten
Michel Guirguis wrote: [Please don't start a new thread for an old problem] > I have a problem with the cumulative distribution function in calculating > derivatives. I am getting a call option figure of 2.5961 while it should > be 2.9081. Could you please help. > >>> S=50 > >>> K=50 > >>> r=0.0

Re: [Tutor] Beautiful Soup

2015-09-29 Thread Peter Otten
Crusier wrote: > I have recently finished reading "Starting out with Python" and I > really want to do some web scraping. Please kindly advise where I can > get more information about BeautifulSoup. It seems that Documentation > is too hard for me. If you tell us what you don't understand and wh

Re: [Tutor] skip/slice more than every second?

2015-09-29 Thread Peter Otten
questions anon wrote: > thankyou but I just realised I wrote the question wrong - > > how do I do the inverse of above > so > hide 1 show 2,3,4 hide 5, show 6,7,8 etc. > > thanks in advance You can use del on a slice: >>> a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14] >>> del a[::4] >>> a [2, 3, 4, 6,

Re: [Tutor] tkinter create a frame and whats the parent

2015-09-23 Thread Peter Otten
David Niklas wrote: > Hello, I was following the doc, and in the beginning he gives an > example where he creates a frame and accesses the main window by the > name of Master. > > http://infohost.nmt.edu/tcc/help/pubs/tkinter/tkinter.pdf I suppose you are asking about """ #!/usr/bin/env python

Re: [Tutor] stx, etx (\x02, \x03)

2015-09-22 Thread Peter Otten
richard kappler wrote: [Richard, please don't top-post. Thank you] > On Tue, Sep 22, 2015 at 8:58 AM, Mark Lawrence > wrote: >> On 22/09/2015 13:37, richard kappler wrote: >>> I have tried: >>> #!/usr/bin/env python >>> >>> with open('input/test.xml', 'r') as f1: >>> with open('mod1.xml'

Re: [Tutor] Creating a match file

2015-09-21 Thread Peter Otten
EILEEN CHURCH CARSON wrote: > I want to write a program that reads in data from two csv files with 6 > columns each. I want it to determines if the data in the first two columns > is the same, and if so read all six columns in that line from each of the > two files into a 12 column output file. >

Re: [Tutor] [newbie] import error after restart (virtualenv)

2015-09-19 Thread Peter Otten
David wrote: > Dear Tutors, > > I am reading through Harry Percival's "Test-Driven Development with > Python". > > As I finished chapter 3 yesterday, I was fully on track, perfectly > aligned with the book. > > Today I restarted my computer, activated the virtualenv in question -- > and get an

Re: [Tutor] Calling instance method in IDLE magically calls __len__?

2015-09-18 Thread Peter Otten
Dino Bektešević wrote: > Hello, > > For full disclosure, I'm using Python2.7 on Ubuntu 14.04. MWE bellow and > at https://bpaste.net/show/3d38c96ec938 (until 2015-09-25 06:29:54, in the > case spaces get messed up). > > class Errors: > def __init__(self): > pass > def toFile(self

Re: [Tutor] More Pythonic?

2015-09-09 Thread Peter Otten
Timo wrote: > Op 09-09-15 om 15:41 schreef Steven D'Aprano: >> On Wed, Sep 09, 2015 at 09:05:23AM -0400, richard kappler wrote: >>> Would either or both of these work, if both, which is the better or more >>> Pythonic way to do it, and why? >> The first works, but isn't really the best way to do i

Re: [Tutor] Fwd: find second occurance of string in line

2015-09-09 Thread Peter Otten
natives? Would > you uninstall lxml to force that one of the alternatives is used? Again, I have not much experience with code that must cope with different environments. I have simulated a missing module (not lxml) with the following trick: $ mkdir missing_lxml $ echo 'raise Impo

Re: [Tutor] More Pythonic?

2015-09-09 Thread Peter Otten
richard kappler wrote: > Would either or both of these work, if both, which is the better or more > Pythonic way to do it, and why? > > ### > > import whatIsNeeded > > writefile = open("writefile", 'a') > > with open(readfile, 'r') as f: > for line in f: > if ke

Re: [Tutor] find second occurance of string in line

2015-09-09 Thread Peter Otten
richard kappler wrote: > On Tue, Sep 8, 2015 at 1:40 PM, Peter Otten <__pete...@web.de> wrote: >> I'm inferring from the above that you do not really want the "second" >> timestamp in the line -- there is no line left intace anyway;) -- but >> rather

Re: [Tutor] Fwd: find second occurance of string in line

2015-09-08 Thread Peter Otten
Albert-Jan Roskam wrote: >> import lxml.etree >> >> tree = lxml.etree.parse("example.xml") >> print tree.xpath("//objectdata/general/timestamp/text()") > > Nice. I do need to try lxml some time. Is the "text()" part xpath as well? Yes. I think ElementTree supports a subset of XPath. __

Re: [Tutor] Fwd: find second occurance of string in line

2015-09-08 Thread Peter Otten
richard kappler wrote: >> Do you want to find just the second occurence in the *file* or the second > occurence within a given tag in the file (and there could be multiple such > tags)? > > There are multiple objectdata lines in the file and I wish to find the > second occurence of timestamp in e

<    1   2   3   4   5   6   7   8   9   10   >