Re: [Tutor] List of tuples

2016-04-20 Thread Alan Gauld via Tutor
On 19/04/16 21:56, isaac tetteh wrote: > I have a list like this > [ > ("name",2344,34, "boy"),("another",345,47,"boy", "last") > ] Assuming this is list_tuple... > for row in list_tuple: > for row2 in row: > return row This can't work because return needs to be inside a function.

Re: [Tutor] Fwd: List of tuples

2016-04-20 Thread Alan Gauld via Tutor
On 20/04/16 06:52, isaac tetteh wrote: >> Thanks things are working good now. The only problem is >> i want to print the for loop output on one line instead of on each line. >> Example [1,2,3,4,5] >> Output >> 1 2 3 4 5 >> I would to do this in Jinja I don;t know what Jinja is but... When yo

Re: [Tutor] The game of nim in python

2016-04-22 Thread Alan Gauld via Tutor
On 22/04/16 13:45, Henderson, Kevin (GE Aviation, US) wrote: > Python to Jython. > > Can you help me with a Jython code for the Nim game? > There shouldn't be much difference between a Jython or Python implementation - unless you are building a GUI of course! > Removing 1-4 sticks out of 13, la

Re: [Tutor] python equivalents for perl list operators?

2016-04-23 Thread Alan Gauld via Tutor
On 23/04/16 01:15, Malcolm Herbert wrote: > @raw = (2, 1, 4, 3); > @grepped = grep { $_ >= 3 } @raw; # (4, 3) grepped = [item for item in raw if item >= 3] > @mapped = map { $_ + 1 } @raw; # (3, 2, 5, 4) mapped = [item +1 for item in raw] or mapped = map(lambda x: x+1, raw) > @sorted =

Re: [Tutor] XML and ElementTree

2016-04-25 Thread Alan Gauld via Tutor
On 25/04/16 17:24, Marco Soldavini wrote: > I've a few questions about parsing XML. I wrote some code that works > but I want to know which are the most intelligent data structures to > parse data to Answer: The ones that suit what you want to do with it. But you haven't told us what you plan on u

Re: [Tutor] Using a dictionary to map functions

2016-04-26 Thread Alan Gauld via Tutor
On 26/04/16 05:30, Colby Christensen wrote: > import re > from store_point import store_point > > try: > infile = open(raw_input("Enter input file name; name.txt:"),'r') > except: > print "Invalid filename" > exit() > > templist = [] > pt_table = {} > cmd_table = {5:"store_point", 19

Re: [Tutor] def __init__(self):

2016-04-26 Thread Alan Gauld via Tutor
On 26/04/16 08:01, Santanu Jena wrote: > Hi, > > Pls let me why > " > def __init__(self): > > " > declaration required, what's the use of this one.Pls explain me in > details. It is used to initialise object instances. For example if you define a class Rectangle that has a length and width and

Re: [Tutor] XML and ElementTree

2016-04-26 Thread Alan Gauld via Tutor
Forwarding to tutor list. Please always use "Reply All" or "Reply List" when responding to the tutor list. On 26/04/16 09:24, Marco Soldavini wrote: > On Tue, Apr 26, 2016 at 2:05 AM, Alan Gauld via Tutor > wrote: >> On 25/04/16 17:24, Marco Soldavini wrote

Re: [Tutor] Is there a library which has this object?

2016-04-28 Thread Alan Gauld via Tutor
On 28/04/16 14:53, Yeh wrote: > Hi, > Is there a library which can return some numbers continuously? You probably want to look at the itertools module. There you can find among others the count() generator function. Others of possible interest include cycle() and repeat() -- Alan G Author of t

Re: [Tutor] Detect the folder of a file

2016-04-28 Thread Alan Gauld via Tutor
On 28/04/16 11:11, Steven D'Aprano wrote: > You know, some day I must learn why people use virtual environments. Me too :-) My co-author included a section in one of her chapters of our recent book, and I duly played with them while reviewing that chapter. But at the end I just deleted it all a

Re: [Tutor] Is there a library which has this object?

2016-04-28 Thread Alan Gauld via Tutor
On 28/04/16 19:08, Yeh wrote: > I just solved my first question by using numpy, as below: You need to post in plain text otherwise the mail system mangles your code, as you can see. > import timeimport numpy as np > start = input("please input the value of start: ")end = input("please input >

Re: [Tutor] vpython help

2016-04-29 Thread Alan Gauld via Tutor
On 29/04/16 00:27, Craig, Daniel Joseph wrote: > I am writing a program where I have a ball with a position and velocity > reach a wall in 3D space. Well done, but vpython is a bit off topic for this list which deals with the core python language and libraries. I notice there is a vpython user

Re: [Tutor] (no subject)

2016-04-29 Thread Alan Gauld via Tutor
On 29/04/16 14:10, Павел Лопатин wrote: > Hello, > I downloaded Python 3.4.3 from python.org, installed it, > but when I tried to run it on my notebook a message appeared The error is about IDLE rather than about Python so its probably worth checking whether python itself runs first. Open a CMD

Re: [Tutor] pytsk

2016-04-29 Thread Alan Gauld via Tutor
On 29/04/16 14:15, Tees, Peter (EthosEnergy) wrote: > Now I want to put what I've learned to good use, based on the > articles by David Cowen at the Hacking Exposed blog > and in particular his series "Automating DFIR - How to series > on programming libtsk with Python" > Can anyone point me to

Re: [Tutor] Sorting a list in ascending order [RESOLVED]

2016-04-29 Thread Alan Gauld via Tutor
On 29/04/16 23:58, Ken G. wrote: >> print ''.join(list1) #making it again as a single string >> > > Thanks, Meena, that is great! I changed your last line to: > > print "".join(list1) and it came out as below: > > 0511414453 > > Another quotation mark was needed. No it wasn't. Meen

Re: [Tutor] Sorting a list in ascending order [RESOLVED]

2016-04-29 Thread Alan Gauld via Tutor
On 30/04/16 00:05, Ken G. wrote: > been able to change over to Python3. I am not together sure if Python3 > is now more stable to use and more commonly use. It is definitely stable and most libraries are now converted (although a few remain v2 only). Availability of libraries is now the only re

Re: [Tutor] Extracting bits from an array

2016-04-29 Thread Alan Gauld via Tutor
On 29/04/16 20:47, Anish Kumar wrote: >> Is the number of bits fixed to four? If so you can shift the bits to the >> right: >> > y = [v>>2 for v in x] > > Right shifting is well defined in Python? Yes, Python has good support for all the common bitwise operations, including the shift right/

Re: [Tutor] Issue with Code

2016-04-30 Thread Alan Gauld via Tutor
On 30/04/16 16:30, Olaoluwa Thomas wrote: > I've attached the scripts in question (created via Notepad++). attachments often get stripped by the mail system as a security risk. Since your code is very short just post it in the mail message as plain text. > The problem with this script is that th

Re: [Tutor] Fwd: Issue with Code

2016-04-30 Thread Alan Gauld via Tutor
On 30/04/16 22:32, Olaoluwa Thomas wrote: > I sent this forwarded email earlier but hadn't subscribed to the mailing > list so I guess that's why I didn't get a response. When you first subscribe all messages are moderated so there is a delay. Plus remember that email is pretty much the lowest pr

Re: [Tutor] Is there a library which has this object?

2016-04-30 Thread Alan Gauld via Tutor
On 30/04/16 08:48, Yeh wrote: > start = input("please input the value of start: ") > end = input("please input the value of end: ") > dur = input("please input the value of dur: ") > array = np.linspace(float(start),float(end),1000) > dur = float(dur)/len(array) > for i in array: > print(float(i))

Re: [Tutor] Issue with Code

2016-04-30 Thread Alan Gauld via Tutor
On 01/05/16 01:16, Alan Gauld via Tutor wrote: > I can't see anything obviously wrong in your code I was too busy focusing on the calculations that I didn't check the 'if' test closely enough. You need to convert your values from strings before comparing them. hours = flo

Re: [Tutor] Issue with Code [SOLVED]

2016-05-01 Thread Alan Gauld via Tutor
On 01/05/16 05:20, Olaoluwa Thomas wrote: > Thank you so much, Alan. That fixed it (See Script 2[SOLVED] below). > > For the purpose of record-keeping, I'm pasting the entire code of all > scripts below as I should have done from the very beginning. > thanks :-) > P.S. How were you able to open

Re: [Tutor] META: Moderation and subscription to the tutor list

2016-05-01 Thread Alan Gauld via Tutor
On 01/05/16 05:18, Steven D'Aprano wrote: > What's your policy here on the tutor list? I don't really have a policy. The list policy, set by my predecessors, is to allow anyone to send mail and encourage them to subscribe. All unsubscribed mail goes to moderation (and there is not very much of i

Re: [Tutor] META: Moderation and subscription to the tutor list

2016-05-01 Thread Alan Gauld via Tutor
On 01/05/16 06:35, c...@zip.com.au wrote: > There seems to me a subjectly large number of very short threads with a > question from someone, a couple of responses from list members, and no > further > reply. > > To me this argues that either newcomers are not subscribed and probably do > not

Re: [Tutor] META: Moderation and subscription to the tutor list

2016-05-01 Thread Alan Gauld via Tutor
On 01/05/16 10:06, Alan Gauld via Tutor wrote: > Quite a lot of people use the digest service, especially lurkers. > (A quick scan of the members lists suggests around 35-40% > of all members use digest). I'd be reluctant to remove a > service that is so widely used. I've

Re: [Tutor] META: Moderation and subscription to the tutor list

2016-05-01 Thread Alan Gauld via Tutor
On 01/05/16 07:23, boB Stepp wrote: > I am in agreement with this as well. I have often wondered if > newcomers are subscribed or not Most are. Several who are not, subscribe very soon after - presumably in response to the intro message. > as after subscription one receives a > very helpful em

Re: [Tutor] Issues converting a script to a functioin (or something)

2016-05-01 Thread Alan Gauld via Tutor
On 01/05/16 12:55, Olaoluwa Thomas wrote: > It computes total pay based on two inputs, no. of hours and hourly rate. While you do specify two inputs you immediately throw them away and ask the user to provide the information. In general it is good practice to separate calculation from input/outpu

Re: [Tutor] Issues converting a script to a functioin (or something) [SOLVED]

2016-05-01 Thread Alan Gauld via Tutor
On 01/05/16 14:38, Olaoluwa Thomas wrote: > Thanks for your feedback. Please do not hesitate to provide more as I shall > email you personally in the future. Please don't do that. a) Bob is a busy man who volunteers his time here, but may have other things to do too. b) The list is here so tha

Re: [Tutor] simple regex question

2016-05-01 Thread Alan Gauld via Tutor
On 01/05/16 17:49, bruce wrote: > Hi. I have a chunk of text code, which has multiple lines. > s=''' > id='CourseId10795788|ACCT2081|002_005_006' style="font-weight:bold;" > onclick='ShowSeats(this);return false;' alt="Click for Class Availability" > title="Click for Class Availability">ACCT208

Re: [Tutor] simple regex question

2016-05-01 Thread Alan Gauld via Tutor
On 01/05/16 20:04, bruce wrote: > Hey all.. > > Yeah, the sample I'm dealing with is html.. I'm doing some "complex" > extraction, and i'm modifying the text to make it easier/more robust.. > > So, in this case, the ability to generate the line is what's needed > for the test.. > But as Peter expl

Re: [Tutor] Dictionary Question

2016-05-02 Thread Alan Gauld via Tutor
On 02/05/16 22:55, isaac tetteh wrote: > > For some reason i cant find reply all . But try this > for key, value in mydic.items(): > If A==value: >Print key or as a function: def findKey(dct, val): for k,v in dct.items(): if v == val: return k mydic = {"A: "

Re: [Tutor] sqlite

2016-05-03 Thread Alan Gauld via Tutor
On 03/05/16 10:09, Crusier wrote: > I am just wondering if there is any good reference which I can learn how to > program SQLITE using Python > > I can not find any book is correlated to Sqlite using Python. You can try my tutorial below. http://www.alan-g.me.uk/tutor/tutdbms.htm If you want v

[Tutor] Digest format changed to MIME

2016-05-05 Thread Alan Gauld via Tutor
As mentioned earlier I've changed the digest format to MIME. If anyone has problems receiving that please let me know offline and we'll try to resolve it. Hopefully this will allow digest users to reply to individual messages and avoid the frequent resending of entire digests. It may even fix the

Re: [Tutor] META: Moderation and subscription to the tutor list

2016-05-08 Thread Alan Gauld via Tutor
On 01/05/16 05:18, Steven D'Aprano wrote: > ...(And I think we should default to > individual emails, not daily digest.) It took me a little while to find this one, but I've checked and the default is to receive individual emails. You need to opt-in to get the digests and opt-out to stop getting

Re: [Tutor] META: Moderation and subscription to the tutor list

2016-05-08 Thread Alan Gauld via Tutor
On 08/05/16 08:59, Alan Gauld via Tutor wrote: > This means you can get > - single emails (default) > - emails plus digest - digest and no emails > - neither (this is my choice because I read via gmane) Sorry, I missed an option... -- Alan G Author of the Learn to Program w

Re: [Tutor] Best Practices with JSON Data

2016-05-08 Thread Alan Gauld via Tutor
On 08/05/16 14:07, Hunter Jozwiak wrote: > I am intending to start work on a Python program that will allow me to > better manage my Digital Ocean droplets, due to the fact that the website > can be at times a bit overkill for some of the basic tasks I want to do. OK, but I have absolutely no id

Re: [Tutor] Practice python

2016-05-08 Thread Alan Gauld via Tutor
On 08/05/16 18:14, monik...@netzero.net wrote: > Can you please recommend a free web class or site that offers > lots of coding exercises in python, Have you tried the Python Challenge web site? > ... intermediate and advanced AND provides solutions. The challenge site gets pretty advanced a

Re: [Tutor] How to make object disappear?

2016-05-09 Thread Alan Gauld via Tutor
On 09/05/16 16:55, boB Stepp wrote: >> class dot: >> def __init__(self, canvas, color): >> self.canvas = canvas >> self.id = canvas.create_oval(15, 15, 30, 30, fill='Blue', >> tags='dot1') >> >> this = dot(canvas, 'blue') You create an inst

Re: [Tutor] is there a better way to do this?

2016-05-09 Thread Alan Gauld via Tutor
On 09/05/16 22:03, Ondřej Rusek wrote: > but for 'tuples in list'... simple: > > data = [] > for record in curs: >data += [record] Couldn't that be abbreviated to: date = list(curs) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/al

Re: [Tutor] postgreSQL + psycopg2

2016-05-09 Thread Alan Gauld via Tutor
On 09/05/16 22:14, nitin chandra wrote: > for line1 in smallLIST1: > design1 = line1[3] > print design1 > nextRow=cursor1.execute("SELECT designation_name FROM designation > WHERE designation_id = %s;", (design1)) > print nextRow > print "" > for row in line1: >

Re: [Tutor] Rate transition from 60hz to 1000hz

2016-05-10 Thread Alan Gauld via Tutor
On 10/05/16 04:08, David Wolfe wrote: > I'm collecting both video and force plate data, and I need to be able to > synchronize the two, so I can make some calculations. The video data is at > 60hz, and the force plate data is at 1000hz. I don't want to truncate the > force plate data. I have no

Re: [Tutor] postgreSQL + psycopg2

2016-05-10 Thread Alan Gauld via Tutor
On 10/05/16 08:33, nitin chandra wrote: > here is the result. > > 1 > ('Supervisor',) > > 1 > Vinayak > Salunke > 1 > > Now I need to remove the braces and quotes .. :) No you don't. Those are just part of the string representation that Python uses when printing a string inside a tuple. If yo

Re: [Tutor] sqlite

2016-05-13 Thread Alan Gauld via Tutor
On 13/05/16 21:25, Neil D. Cerutti wrote: > From your tutorial: > > query = '''INSERT INTO Address > (First,Last,House,Street,District,Town,PostCode,Phone) > Values ("%s","%s","%s","%s","%s","%s","%s","%s")''' %\ > (first, last, house, street, dist

Re: [Tutor] Curses Module

2016-05-16 Thread Alan Gauld via Tutor
On 15/05/16 22:45, Rosen, Brian - 2016 wrote: >...In my current assignment, I would like to import the curses module > into either Python 2.7 or Python 3.4. However, > whenever I attempt to import it, there is an Import Error Curses is only available in the standard library on Unix-like operating

Re: [Tutor] Adding to a dict through a for loop confusion.

2016-05-17 Thread Alan Gauld via Tutor
On 17/05/16 09:28, Chris Kavanagh wrote: > # Example #1 > cart_items = ['1','2','3','4','5'] > > cart = {} > > for item in cart_items: > cart['item'] = item 'item' is a literal string. It never changes. So you keep overwriting the dict entry so that at the end of the loop the dict contains

Re: [Tutor] Adding to a dict through a for loop confusion.

2016-05-17 Thread Alan Gauld via Tutor
On 17/05/16 23:56, Chris Kavanagh wrote: > So, by putting quotes around a dict key, like so dict["key"] or in my case > cart["item"] this makes the dict have ONE key. The loop assigns the > cart_items to this ONE key until the end of the loop, and I'm left with > {'item': 5}. . . > > Where as if

Re: [Tutor] genfromtxt and dtype to convert data to correct format

2016-05-17 Thread Alan Gauld via Tutor
On 17/05/16 18:11, Ek Esawi wrote: > output comes out in the correct format (the desired output as shown below). > I used converters to covert time and date values, but all came out in > string format (output below). What makes you think they are strings? I would expect to see quote signs if they

Re: [Tutor] genfromtxt and dtype to convert data to correct format

2016-05-18 Thread Alan Gauld via Tutor
On 18/05/16 14:14, Ek Esawi wrote: > OPS! Sorry, I made a mistake on the posting. My output is in a string > format as shown below. I want the 1st and 8th integers, the 3rd string > which is OK as, the 2nd date and the rest time. You will need to convert the integers manually I suspect with int(r

Re: [Tutor] genfromtxt and dtype to convert data to correct format

2016-05-19 Thread Alan Gauld via Tutor
On 19/05/16 01:31, Ek Esawi wrote: > Thanks Alan! > > Taking the strtime off did not work either and printed dattime.dattime(very > long date format). But isn't that just the representation of a datetime object (which is what strptime produces)? In other words it's an object not a string. Can y

Re: [Tutor] genfromtxt and dtype to convert data to correct format

2016-05-19 Thread Alan Gauld via Tutor
On 19/05/16 12:51, Ek Esawi wrote: > Thanks again! > > I tried a combination of the suggestions and still not getting what i want. > > Here are the original code, file, and output. > > CODE > > mport csv; import numpy as np; from datetime import datetime, date, time > > CF = lambda date: datet

Re: [Tutor] SQLite

2016-05-19 Thread Alan Gauld via Tutor
On 19/05/16 10:03, Crusier wrote: > c.execute('''CREATE TABLE stocks > (code text)''') > > # Insert a row of data > List = ['1', '2', '3', '4', '5', '6', '7', > '8', '9', '00010', '00011', '00012'] > > c.executemany('INSERT INTO stocks VALUES (?)'

Re: [Tutor] FTP file transfer stops, no error given

2016-05-19 Thread Alan Gauld via Tutor
On 19/05/16 15:11, Craig Jackson wrote: > ftp. In a nutshell the problem is that if the two objectives are > combined into one Python script, ftp stops uploading in the middle of > the file, but if the same code is split into two files, web page > creation in one script and ftp in another, and the

Re: [Tutor] FTP file transfer stops, no error given

2016-05-19 Thread Alan Gauld via Tutor
On 19/05/16 19:01, Craig Jackson wrote: > Adding the parentheses worked. So sorry for taking your time. I'm new > to Python and not at all a programmer. Thanks for your help. No trouble, that's what the list is here for. Just remember next time to post the code that fails rather than the code tha

Re: [Tutor] Getting started in testing

2016-05-19 Thread Alan Gauld via Tutor
On 19/05/16 20:34, Terry Carroll wrote: > Is anyone aware of any good tutorials on testing one's Python code? I'm not a big fan of video tutorials but I recently had to teach myself Junit testing (and mockito) in Java and I found that Youtube videos really helped. I know there are similar videos o

Re: [Tutor] What these Python user-defined functions do?

2016-05-21 Thread Alan Gauld via Tutor
On 21/05/16 02:21, Max Jegers wrote: > class View: > def __init__(self): > self.handle = None > > def order(self, n): > return hostviewOrder(handle, self.handle, n) > > def put(self, fieldName, value, verify=1): > if verify == True: >

Re: [Tutor] Python 3: string to decimal conversion

2016-05-22 Thread Alan Gauld via Tutor
On 22/05/16 14:19, US wrote: >>with open(file) as csvfile: >>records = csv.reader(csvfile, quoting=csv.QUOTE_NONE) > [...] >>for row in records: > [...] >>try: >>expenses[ts.Date(row[0]).month] += > decimal.Decimal(row[4]) >>

Re: [Tutor] Python 3: string to decimal conversion

2016-05-23 Thread Alan Gauld via Tutor
On 23/05/16 02:45, US wrote: > I tried the float() function instead of decimal.Decimal and got an > error message: could not convert string to float: '($75.59)'. The problem is that the functions don;t recognize the parens as a negative sign. You will need to convert them yourself. I suggest you

Re: [Tutor] which is best python 2 or python3

2016-05-23 Thread Alan Gauld via Tutor
On 23/05/16 08:54, Palanikumar Gopalakrishnan wrote: > Hi buddies, > I read one article on internet which is said python 2 > and python3 is totally different in programming. > As a beginner which i prefer for my learning, python 2 or python3 ? Nowadays the only real justificat

Re: [Tutor] I've subscribed to your service, no confirmation yet. I'm looking for a tutor and I need help with some code.

2016-05-24 Thread Alan Gauld via Tutor
Re your subject... This is a mailing list. You subscribe and you should receive mails sent to the list. If you have a question send it to the list (like you did here) and one or more of the list members will hopefully respond. The more specific your question the more precise will be the response. T

Re: [Tutor] Learning Regular Expressions

2016-05-24 Thread Alan Gauld via Tutor
On 23/05/16 23:08, Terry--gmail wrote: > scripted worked great without the notes! I'd like to know what it is in > the below Tripple-Quoted section that is causing me this problem...if > anyone recognizes. In IDLE's script file..._it's all colored green_, > which I thought meant Python was goi

[Tutor] Fwd: Re: I've subscribed to your service, no confirmation yet. I'm looking for a tutor and I need help with some code.

2016-05-24 Thread Alan Gauld via Tutor
the telnet lib and just type; telnet 10.45.34.80 and I'll be able to get to my controller??? Thank you for helping me :) ...you cannot direct the wind but you can adjust your sails... *Angelia Spencer (Angie)* -------- *Fro

[Tutor] Fwd: Re: I've subscribed to your service, no confirmation yet. I'm looking for a tutor and I need help with some code.

2016-05-24 Thread Alan Gauld via Tutor
Forwarding to the list. Please use reply-all to respond to list messages. Also please use plain text as HTML messages often result in code listings being corrupted, especially the spacing, which is very important in Python. Forwarded Message > I just opened the python IDLE 3.5

Re: [Tutor] Fwd: Re: I've subscribed to your service, no confirmation yet. I'm looking for a tutor and I need help with some code.

2016-05-25 Thread Alan Gauld via Tutor
> I do get the >>> in the python IDLE but within my python script/file can > I telnet to my controller? Keep in mind when I do log into my controller > it's command line driven. One thing that occurred to me is that you may be better off using the subprocess module to start an interactive telnet

Re: [Tutor] Fwd: Re: I've subscribed to your service, no confirmation yet. I'm looking for a tutor and I need help with some code.

2016-05-25 Thread Alan Gauld via Tutor
On 25/05/16 14:11, Angelia Spencer wrote: > in your code below you're telnet-ing to a website, No, I'm telnetting to a server with the IP address mysite.com (which is obviously fictitious, but could be any valid IP address). There is nothing that says it's a web site. (And even some web sites migh

Re: [Tutor] Baffling problem with a list of objects sharing a property

2016-05-25 Thread Alan Gauld via Tutor
On 25/05/16 17:05, Alex Hall wrote: > Python for a while so eventually unsubscribed. Welcome back Alex :-) > Now I'm using Python for work, and have run into a problem that has me > baffled. It's as though a bunch of class instances in a list are sharing a > single property. They are. You've s

Re: [Tutor] Fwd: Re: I've subscribed to your service, no confirmation yet. I'm looking for a tutor and I need help with some code.

2016-05-25 Thread Alan Gauld via Tutor
On 25/05/16 17:19, Alan Gauld via Tutor wrote: > Here is an actual session using a public telnet site: > >>>> import telnetlib >>>> tn = telnetlib.Telnet('telehack.com') >>>> response = tn.read_some() >>>> b'\r\nConnected

Re: [Tutor] Logging exceptions, but getting stderr output instead

2016-05-25 Thread Alan Gauld via Tutor
On 25/05/16 19:11, Alex Hall wrote: > As a quick aside, is there an easy way to halt script execution for some > exceptions? Right now, catching them means that execution continues, but I > sometimes want to log the problem and then abort the script, as the error > means it shouldn't continue. Tha

Re: [Tutor] Newcomer with organizational questions

2016-05-26 Thread Alan Gauld via Tutor
On 26/05/16 23:34, Max Jegers wrote: > that I wrote a reply with a thank you and a follow-up question, only to > discover that I don’t see a way to send it. A mailing list works by email, so you reply as you would to any email. If you use Reply it goes to the person who sent the email. If you use

Re: [Tutor] Correct use of model-view-controller design pattern

2016-05-29 Thread Alan Gauld via Tutor
On 29/05/16 05:33, boB Stepp wrote: > I am currently mulling over some information Alan passed along a while > back on using the model-view-controller design pattern (Would > 'architectural pattern' be a better choice of phrase?). Either is appropriate. Design Pattern is more usual, largely beca

Re: [Tutor] Correct use of model-view-controller design pattern

2016-05-30 Thread Alan Gauld via Tutor
On 29/05/16 05:33, boB Stepp wrote: As promised I'm back so will try to answer these... > Some other questions: > > 1) If I were to add code to filter user inputs, which file is the > logical place to place such code? My current impression is that it > should go in the controller, but I could

Re: [Tutor] Learning Regular Expressions

2016-05-30 Thread Alan Gauld via Tutor
On 30/05/16 18:21, dirkjso...@gmail.com wrote: > I moved my notes that contained any '\'s to a different python file. > However, if we run it, we get the error I was having. Here's the > script: Runs fine for me. Can you run it using the python command line interpreter rather than IDLE? Do you s

Re: [Tutor] Study Tips

2016-05-30 Thread Alan Gauld via Tutor
On 30/05/16 06:45, Steve Lett wrote: > Out of a long list of books that I have collected ( python, Blender, etc ) > I have decided to start on Introducing Python (hard copy 2nd Ed, ebook 3rd > ed) by Bill Lubanovic. Before that I was going to start with Python > Programming for the Absolute Beginn

Re: [Tutor] Correct use of model-view-controller design pattern

2016-05-31 Thread Alan Gauld via Tutor
On 31/05/16 02:25, boB Stepp wrote: > This "views register with models" and "registered views" terminology > is unfamiliar to me. Googling suggests registered views is referring > to a dynamically generated presentation, perhaps in the sense of a db No, this is different. Try googling publish-su

Re: [Tutor] Correct use of model-view-controller design pattern

2016-05-31 Thread Alan Gauld via Tutor
On 31/05/16 02:16, boB Stepp wrote: > I perhaps see a general principle developing here: Before passing > data elsewhere, the data should be validated and in a form suitable > for where it is being sent. Correct. > By "business service" are you intending this to mean a totally > different app

Re: [Tutor] Help with 'if' statement and the concept of None

2016-05-31 Thread Alan Gauld via Tutor
On 31/05/16 16:16, marat murad via Tutor wrote: > program whose code I have pasted below. The author introduced a new way of > coding the Boolean NOT operator with the 'if' statement I have highlighted > the relevant area,apparently this if statement actually means if money != > 0,which I underst

Re: [Tutor] Python OLS help

2016-05-31 Thread Alan Gauld via Tutor
On 31/05/16 16:30, Vadim Katsemba wrote: > Hello there, I am having trouble running the Ordinary Least Squares (OLS) > regression on Spyder. I had no idea what Spyder was but a Google search says its an IDE somewhat akin to matlab or IPython... It also has a discussion group: http://groups.googl

Re: [Tutor] Study Tips

2016-06-01 Thread Alan Gauld via Tutor
On 01/06/16 20:06, Anindya Mookerjea wrote: > Hi experts, > > I am going to start learning Python and have got no coding > experience/knowledge whatsoever . So Python would be my first programming > language Start with one of the tutorials on the non-programmers page of python.org http://wiki.py

Re: [Tutor] OrderedDict?

2016-06-01 Thread Alan Gauld via Tutor
On 01/06/16 16:36, Alex Hall wrote: > I'm trying to find the OrderedDict documentation. I found one page, but it > wasn't very clear on how to actually make an OrderedDict. Plus, an empty > constructor in Python's interpreter returns an error that the class doesn't > exist It's in the collections

[Tutor] Use of None (was: Re: Tutor Digest, Vol 147, Issue 52)

2016-06-01 Thread Alan Gauld via Tutor
On 01/06/16 12:43, marat murad via Tutor wrote: > Thanks for your replies,I think I understand it much better now. I Also I > wanted to know what the 'None' does in the second program. Please make the subject something meaningful and delete all the excess messages. we have all seen them already an

Re: [Tutor] Tkinter and threading

2016-06-02 Thread Alan Gauld via Tutor
On 02/06/16 14:40, Marco Soldavini wrote: > What if I want to run another loop beside the graphical interface in > the same python script? You need to do it in a separate thread. Keep the Tkinter loop on your main thread and use it to trigger actions. > For example a state machine with a var sta

Re: [Tutor] Semantic Error: Trying to access elements of list and append to empty list with for loop

2016-06-02 Thread Alan Gauld via Tutor
On 02/06/16 18:05, Olaoluwa Thomas wrote: > lst = list() > for line in fhand: > words = line.split() words is now a list of words a test that a portion of my code was working) > lst.append(words) So you append that list to lst and get a list of lists. Try using + instead: lst += words

Re: [Tutor] Practice Exercises for Beginner ?

2016-06-03 Thread Alan Gauld via Tutor
On 02/06/16 21:43, Andrei Colta wrote: > Hi, > > Anyone can recommend practical work on learning python.. seems reading and > reading does not helping. Other have recommended starting a project and that's always the best way. But if you are really stuck for ideas try the Python Challenge. It's

Re: [Tutor] Desperately need help to uninstall python from my mac

2016-06-03 Thread Alan Gauld via Tutor
On 03/06/16 17:18, Christian Carbone via Tutor wrote: > As the subject line indicates, I really need help uninstalling python on my > mac.. You almost certainly don;t want to to do that! Your Mac will stop working properly, it uses Python. That's why its installed by default on Macs. > The reas

Re: [Tutor] Cmd line not correctly interpreted

2016-06-04 Thread Alan Gauld via Tutor
On 04/06/16 02:01, Alan Outhier wrote: > I'm working on a Python script to call "sox" to convert ;ogg files to .mp3s. 1outname=fname+".mp3" 2fname=ReSpace(fname) # substitute " " with "\ " 3outname=ReSpace(outname) 4cmdline="sox " + fname + " " +outname 5print cmdline 6rt

Re: [Tutor] Python Setup Help

2016-06-08 Thread Alan Gauld via Tutor
On 08/06/16 03:24, Vincent Trost via Tutor wrote: > Hi, > I'm looking for help on the proper installation of Python and the Text > editor, Atom. OK, Lets break those into two separate activities. Start with Python. > we downloaded Enthought Canopy and used that for some scientific Python work.

Re: [Tutor] Command statement work well on interactive mode, which running as pf file it throws error object has no attribute '__getitem__'

2016-06-09 Thread Alan Gauld via Tutor
On 09/06/16 08:33, Joseph John wrote: > Now when I create a *.py file with all the above steps and run it, I am > getting error > Traceback (most recent call last): > File "./ReadingDataFrom1X.py", line 10, in > c = sheet['A1'] > TypeError: 'Worksheet' object has no attribute '__getitem__'

Re: [Tutor] Command statement work well on interactive mode, which running as pf file it throws error object has no attribute '__getitem__'

2016-06-10 Thread Alan Gauld via Tutor
On 09/06/16 10:03, Joseph John wrote: > itsupport@Server-A:~$ cat ReadingDataFrom1X.py > #!/usr/bin/python > import openpyxl > wb = openpyxl.load_workbook('1XDataUserMDN.xlsx') > wb.get_sheet_names() > sheet= wb.get_sheet_by_name('SQL Results') > sheet.title > print sheet.title > print sheet['A1']

Re: [Tutor] Loop in pre-defined blocks

2016-06-10 Thread Alan Gauld via Tutor
On 10/06/16 23:43, Jignesh Sutar wrote: > Is there a better way to code the below than to specify blocks as I have. > Ideally I'd like to specify blocks simply as *blocks=(12,20,35)* > > blocks=[(1,12), (13,20), (25,35)] > for i,j in enumerate(blocks): > for x in xrange(blocks[i][0],blocks[i][

[Tutor] Fwd: Re: Loop in pre-defined blocks

2016-06-10 Thread Alan Gauld via Tutor
Forwarding to tutor list. Always use Reply All when responding to list mail. > Sorry, to be a little bit more descriptive. I'd like to loop from 1 to 35 > but within this loop there are divisions which I need to prefix that > particular division number. > My output would look like this: >

Re: [Tutor] Loop in pre-defined blocks

2016-06-13 Thread Alan Gauld via Tutor
On 13/06/16 08:46, Ek Esawi wrote: > Here is a beginner code that might work for you. Best of luck. EK > > b=[12, 20, 35] > > for i in range(len(b)): > if i==0: > c=0 > else: > c=b[i-1] > for j in range(c, b[i]): > print(i+1,j+1) The problem here is

Re: [Tutor] Howto display progress as cmd is being executed via subprocess ?

2016-06-13 Thread Alan Gauld via Tutor
On 13/06/16 17:50, Ramanathan Muthaiah wrote: > Am aware of the module called 'progressbar' that can do this magic of > displaying progress as the cmd is executed. I'm not familiar with it, I don't believe its in the standard library? So I can only offer generalized advice. > def main(): >

Re: [Tutor] Python ODBC driver for Oracle 9

2016-06-13 Thread Alan Gauld via Tutor
On 13/06/16 11:47, Joseph John wrote: > I am trying to connect Python to Oracle 9 DB, checked for python ODBC > driver for oracle. Please be clear. Are you looking for an ODBC driver that will work with Oracle 9? Or are you looking for a Python DBAPI driver for Oracle 9? Those are two different

Re: [Tutor] Hello everybody

2016-06-13 Thread Alan Gauld via Tutor
On 13/06/16 20:55, Влад wrote: >Hi. I've just begin with Python? I'm 34. Is it late or what? If it is - I >will cut it out. What you think guys? No you are just a young whippersnapper. I've had students use my tutorial in their 70s (and in their pre-teens too) But is this also your start

Re: [Tutor] capture output from a subprocess while it is being produced

2016-06-14 Thread Alan Gauld via Tutor
On 14/06/16 21:03, Albert-Jan Roskam wrote: > from subprocess import Popen, PIPE > from threading import Thread > from collections import deque > import sys > import time > import os.path > > > def process(dq): > """Run a commandline program, with lots of output""" > cwd = os.path.dirnam

Re: [Tutor] rock paper scissor lizard spock help

2016-06-14 Thread Alan Gauld via Tutor
On 14/06/16 11:18, Katelyn O'Malley wrote: > Hi I am just getting into python and I am trying to create a rock paper > scissor lizard spock game for 3 people and I cannot figure out the scoring The scoring of any ganme is the bit that makes it unique, so we would need to know the scoring rules to

Re: [Tutor] Py 2.4.4: Inheriting from ftplib.FTP()

2016-06-16 Thread Alan Gauld via Tutor
On 16/06/16 16:38, boB Stepp wrote: > class FTPFiles(FTP, object): > """FTP files to Windows server location(s).""" OK, First comment. You describe this as an action(verb) rather than a noun. Classes should represent nouns (objects) not actions. FTP represents a protocol connection with which

Re: [Tutor] Py 2.4.4: Inheriting from ftplib.FTP()

2016-06-17 Thread Alan Gauld via Tutor
On 17/06/16 16:41, boB Stepp wrote: >> Inheritance is a powerful tool but it carries lots of potential for >> problems too,... > > I looked up LSP last night. I can see how I can easily get burned > even on something seemingly simple. One example, which I imagine is > often used, is of a square

Re: [Tutor] help with comparing list of tuples in python 2

2016-06-17 Thread Alan Gauld via Tutor
On 17/06/16 20:18, Lulu J wrote: > I have a list of dictionaries. Each dictionary has a word and its position > in the text the positions are in the form of a tuple. > Here is an example: > [ > {'position': (5, 4), 'term': u'happy',}, > {'position': (5, 5), 'term': u'something'} > ] > > for the

Re: [Tutor] Why are expressions not allowed as parameters in function definition statements?

2016-06-18 Thread Alan Gauld via Tutor
On 18/06/16 20:04, boB Stepp wrote: > py3: def d(row, col/2, radius=5): > File "", line 1 > def d(row, col/2, radius=5): > ^ > SyntaxError: invalid syntax > > And this surprised me. It seems that only identifiers are allowed as > parameters in a function definition statem

Re: [Tutor] Correct use of model-view-controller design pattern

2016-06-19 Thread Alan Gauld via Tutor
On 19/06/16 05:18, boB Stepp wrote: > code, I am left scratching my head. My main issue is what am I aiming > at for a final CLI display of a circle? This is not such a simple > thing! First, what are the units for a circle's radius in a CLI? If > it is 1 radius unit = 1 character, then your c

  1   2   3   4   5   6   7   8   9   10   >