Re: [Tutor] question / decision tree

2015-08-03 Thread Laura Creighton
In a message of Mon, 03 Aug 2015 08:58:43 +0100, matej taferner writes: hi guys, I am wondering if there is a python solution for the problem I am currently dealing with. I need to build a decision tree based questionnaire which helps users to find the right answer. As a final product of this

[Tutor] question / decision tree

2015-08-03 Thread matej taferner
hi guys, I am wondering if there is a python solution for the problem I am currently dealing with. I need to build a decision tree based questionnaire which helps users to find the right answer. As a final product of this decision tree app I need a clickable buttons ready to be embedded into the

Re: [Tutor] question / decision tree

2015-08-03 Thread memilanuk
On 08/03/2015 02:38 AM, matej taferner wrote: Or maybe should I go with the tkinter? As a final product of this decision tree app I need a clickable buttons ready to be embedded into the website which will guide customer(s) to desired answer(s). The two aren't exactly compatible. Tkinter

Re: [Tutor] Question About Image Processing in Python

2015-05-28 Thread Todd
On Thu, May 28, 2015 at 1:05 PM, Terry Reedy tjre...@udel.edu wrote: On 5/28/2015 6:34 AM, Serge Christian Ibala wrote: I want to use the following package “numpy, matplotib, mahotas, ipython OpenCV and SciPy opencv seems to be the only one not available for 3.x. OpenCV 3 (which is

[Tutor] Question About Image Processing in Python

2015-05-28 Thread Serge Christian Ibala
Hello All, I want to know which version of Python is compatible (or can be associated with which version of which tools or package for image processing) I am working under Window and it is so complicated to find out which version of which tool goes with which other version? I want to use

Re: [Tutor] Question About Image Processing in Python

2015-05-28 Thread Oscar Benjamin
On 28 May 2015 at 11:34, Serge Christian Ibala christian.ib...@gmail.com wrote: Hello All, I want to know which version of Python is compatible (or can be associated with which version of which tools or package for image processing) I am working under Window and it is so complicated to find

Re: [Tutor] Question About Image Processing in Python

2015-05-28 Thread Sturla Molden
Serge Christian Ibala christian.ib...@gmail.com wrote: Or what is the recommendation of Python for image processing? Basic setup everyone should have: Python NumPy SciPy (e.g. scipy.ndimage) Cython C and C++ compiler matplotlib scikit-image scikit-learn pillow Also consider: mahotas tifffile

[Tutor] Question for Strategy for Directory Monitor

2015-04-02 Thread Saran Ahluwalia
Good Evening : Here is what I want me program to do: • *Monitor* a folder for files that are dropped throughout the day • When a file is dropped in the folder the program should scan the file o IF all the contents in the file have the same length (let's assume line length) o THEN the file

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-27 Thread Alan Gauld
On 27/11/14 04:18, boB Stepp wrote: Note that this principle is critical to Python, otherwise functions couldn't call each other, or even built-ins! If you have two functions: def f(): return g() def g(): return Hello! g is a global variable and f() can see it, otherwise it couldn't call it.

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-27 Thread Steven D'Aprano
On Wed, Nov 26, 2014 at 10:18:55PM -0600, boB Stepp wrote: So any variables lower in the program are accessible to those above it? No, that can't be the explanation. Think of this: b = a + 1 a = 2 That will fail because when the b = a + 1 line is executed, a doesn't exist yet so there is no

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-27 Thread boB Stepp
On Thu, Nov 27, 2014 at 4:51 AM, Alan Gauld alan.ga...@btinternet.com wrote: On 27/11/14 04:18, boB Stepp wrote: [...] So any variables lower in the program are accessible to those above it? No. Its not whether they are defined above or below each other its the level of indentation. Both

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-27 Thread boB Stepp
On Thu, Nov 27, 2014 at 4:56 AM, Steven D'Aprano st...@pearwood.info wrote: On Wed, Nov 26, 2014 at 10:18:55PM -0600, boB Stepp wrote: So any variables lower in the program are accessible to those above it? No, that can't be the explanation. Think of this: b = a + 1 a = 2 That will fail

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-27 Thread Steven D'Aprano
On Thu, Nov 27, 2014 at 09:00:48AM -0600, boB Stepp wrote: Level of indentation is the key? Can you give me an example, not involving functions, where a variable is defined at an inner level of indentation, but is not accessible at the outermost level of indentation? Classes and functions

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-27 Thread Steven D'Aprano
On Thu, Nov 27, 2014 at 09:13:35AM -0600, boB Stepp wrote: On Thu, Nov 27, 2014 at 4:56 AM, Steven D'Aprano st...@pearwood.info wrote: On Wed, Nov 26, 2014 at 10:18:55PM -0600, boB Stepp wrote: So any variables lower in the program are accessible to those above it? No, that can't be the

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-27 Thread boB Stepp
On Thu, Nov 27, 2014 at 9:33 AM, Steven D'Aprano st...@pearwood.info wrote: On Thu, Nov 27, 2014 at 09:00:48AM -0600, boB Stepp wrote: [...] But there is a subtlety that you may not expect: py class Tricky: ... print(x) ... x = inner ... print(x) ... outer inner Actually,

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-27 Thread Dave Angel
On 11/27/2014 11:07 AM, boB Stepp wrote: x = outer def tricky_func2(): y = x print(x) tricky_func2() outer So why does not print(x) see the global x and instead looks for the local x? The function is compiled during the import (or initial load if it's a

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-27 Thread Alan Gauld
On 27/11/14 16:07, boB Stepp wrote: Alan's reference to indentation level had me trying to prove the opposite--unsuccessfully. Yeah, I probably over-simplified there in response to your assumption that it was the order that mattered. It's really whether they are inside a function or class -

[Tutor] Question about why a list variable is apparently global.

2014-11-26 Thread boB Stepp
Python 2.4.4 Solaris 10 #!/usr/bin/env python from Tkinter import * def printLabel(): print Button number , var.get(), was pressed. print You selected this option:, l[var.get() - 1][0] root = Tk() root.title(ROI List Creator) root.geometry(newGeometry='225x230+900+300')

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-26 Thread Alan Gauld
On 26/11/14 23:23, boB Stepp wrote: def printLabel(): print Button number , var.get(), was pressed. print You selected this option:, l[var.get() - 1][0] ... buttonNumber = [] l = [(Brain_Partial, 1), (Brain_Whole, 2), (Head Neck, 3), (Chest, 4),

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-26 Thread Steven D'Aprano
On Wed, Nov 26, 2014 at 05:23:40PM -0600, boB Stepp wrote: Python 2.4.4 Solaris 10 #!/usr/bin/env python from Tkinter import * def printLabel(): print Button number , var.get(), was pressed. print You selected this option:, l[var.get() - 1][0] root = Tk() root.title(ROI

Re: [Tutor] Question about why a list variable is apparently global.

2014-11-26 Thread boB Stepp
On Wed, Nov 26, 2014 at 6:20 PM, Steven D'Aprano st...@pearwood.info wrote: On Wed, Nov 26, 2014 at 05:23:40PM -0600, boB Stepp wrote: [...] First question: How can the printLabel() function see the list variable, l, defined outside of this function? I thought that functions only had access to

[Tutor] question on array Operation

2014-10-29 Thread jarod...@libero.it
Dear All, I have a long matrix where I have the samples (1to n) and then I have (1to j )elements. I would like to count how many times each j element are present on each samples. So the question is which is the best algoritm for obtain the results. The result I want is a table like that.

Re: [Tutor] question on array Operation

2014-10-29 Thread Peter Otten
jarod...@libero.it wrote: Dear All, I have a long matrix where I have the samples (1to n) and then I have (1to j )elements. I would like to count how many times each j element are present on each samples. So the question is which is the best algoritm for obtain the results. The result

Re: [Tutor] question on array Operation

2014-10-29 Thread Alan Gauld
On 29/10/14 16:08, jarod...@libero.it wrote: I have a long matrix where I have the samples (1to n) and then I have (1to j )elements. I would like to count how many times each j element are present on each samples. That probably makes sense to you but it doesn't to me. Lets assuyme you have

Re: [Tutor] question on array Operation

2014-10-29 Thread Steven D'Aprano
On Wed, Oct 29, 2014 at 05:08:28PM +0100, jarod...@libero.it wrote: Dear All, I have a long matrix where I have the samples (1to n) and then I have (1to j )elements. I would like to count how many times each j element are present on each samples. Jarod, looking at your email address, I

Re: [Tutor] Question on a select statement with ODBC

2014-10-23 Thread Al Bull
-Original Message- From: Tutor [mailto:tutor-bounces+a.bull=pubdmgroup@python.org] On Behalf Of Alan Gauld Sent: Wednesday, October 22, 2014 12:13 PM To: tutor@python.org Subject: Re: [Tutor] Question on a select statement with ODBC On 22/10/14 16:06, Al Bull wrote: I don't think I

Re: [Tutor] Question on a select statement with ODBC

2014-10-23 Thread Peter Otten
Al Bull wrote: Quick question then... Does this do the trick? I may have misunderstood your original question; do you want to delete records from the database or from the Python list? Your code below will do the latter, once you have fixed the bugs. Currentrecord = 1 While

Re: [Tutor] Question on a select statement with ODBC

2014-10-22 Thread Al Bull
-Original Message- From: Tutor [mailto:tutor-bounces+a.bull=pubdmgroup@python.org] On Behalf Of Alan Gauld Sent: Tuesday, October 21, 2014 6:42 PM To: tutor@python.org Subject: Re: [Tutor] Question on a select statement with ODBC On 21/10/14 19:57, Al Bull wrote: have multiple

Re: [Tutor] Question on a select statement with ODBC

2014-10-22 Thread Alan Gauld
On 22/10/14 16:06, Al Bull wrote: I don't think I explained the problem properly. I have several hundred thousand records in the ORD table. There are many instances of records with identical ORD_DBASUB values. Where duplicates exist, I only want to keep the most current record. Ah, OK

[Tutor] Question on a select statement with ODBC

2014-10-21 Thread Al Bull
Windows 7.0 Python 3.3.4 I am accessing a database table via ODBC. The table I am accessing can have multiple records per ord_dbasub. Is there a way I can structure the select statement to retrieve only the most current record (based on ord_date)? I used to program in PL/I and assembly in the

[Tutor] question 1

2014-09-20 Thread Clayton Kirkwood
I'm ramping slowly unfortunately. How does one go about knowing which module to import to make certain functions work? I have a read() that fails because there is no definition for it. I am using the Wing IDE. I have traversed much of the developer's guide and can't find any certainty.

Re: [Tutor] question 1

2014-09-20 Thread Danny Yoo
On Sat, Sep 20, 2014 at 3:20 PM, Clayton Kirkwood c...@godblessthe.us wrote: I’m ramping slowly unfortunately. How does one go about knowing which module to import to make certain functions work? I have a read() that fails because there is no definition for it. Specific details may help here.

Re: [Tutor] question 1

2014-09-20 Thread Danny Yoo
Secondarily, why can you import a module without it importing all of its daughters? The act of importing a module is recursive: if you import a module, and that module itself has import statements, then Python will do the import of the child modules too. And so forth. Hi Deb, Oh! By the

Re: [Tutor] question 1

2014-09-20 Thread Steven D'Aprano
Hi Clayton, and welcome. My responses are interleaved between your questions below. On Sat, Sep 20, 2014 at 03:20:09PM -0700, Clayton Kirkwood wrote: I'm ramping slowly unfortunately. How does one go about knowing which module to import to make certain functions work? Experience, practice,

[Tutor] Question on List of Dict

2014-09-19 Thread Sunil Tech
Hi all, tes = [{'a': 1, 'b': 'this', 'c': 221}, {'a': 2, 'b': 'this', 'c': 215}, {'a': 1, 'b': 'is', 'c': 875}, {'a': 1, 'b': 'sentence', 'c': 874}, {'a': 2, 'b': 'another', 'c': 754}, {'a': 2, 'b': 'word', 'c': 745}] The above one is the result form the DB. I

Re: [Tutor] Question on List of Dict

2014-09-19 Thread Danny Yoo
{'a': 2, 'b': 'another', 'c': 754}, {'a': 2, 'b': 'word', 'c': 745} if the value of the 'a' is same, then all those other values of the dict should be merged/clubbed. Can you write a function that takes two of these and merges them? Assume that they have the same 'a'. Can you

Re: [Tutor] Question on List of Dict

2014-09-19 Thread Sunil Tech
Danny, i wrote a method called *merge *below can you be little clear with an example I wrote something like this ​​ ids = [] for i in tes: if i['a'] not in ids: ids.append(i['a']) print ids def merge(ids, tes): for jj in ids: txt = '' for i in tes:

Re: [Tutor] Question on List of Dict

2014-09-19 Thread Danny Yoo
On Sep 19, 2014 12:28 AM, Danny Yoo d...@hashcollision.org wrote: {'a': 2, 'b': 'another', 'c': 754}, {'a': 2, 'b': 'word', 'c': 745} if the value of the 'a' is same, then all those other values of the dict should be merged/clubbed. Can you write a function that takes

Re: [Tutor] Question on List of Dict

2014-09-19 Thread Sunil Tech
Danny i did it like this result_dict = {} for i in tes: if i['a'] in result_dict: temp = result_dict[i['a']] temp['b'].append(i['b']) temp['c'].append(i['c']) temp['a'] = i['a'] result_dict[i['a']] = temp else: result_dict[i['a']] = {

Re: [Tutor] Question on List of Dict

2014-09-19 Thread Peter Otten
Sunil Tech wrote: Danny i did it like this result_dict = {} for i in tes: if i['a'] in result_dict: temp = result_dict[i['a']] temp['b'].append(i['b']) temp['c'].append(i['c']) temp['a'] = i['a'] result_dict[i['a']] = temp else:

Re: [Tutor] Question on List of Dict

2014-09-19 Thread Sunil Tech
Thank you Peter Otten, actually i should study about the collections and defaultdict like how and where these can be used and its advantage. On Fri, Sep 19, 2014 at 5:59 PM, Peter Otten __pete...@web.de wrote: Sunil Tech wrote: Danny i did it like this result_dict = {} for i in tes:

[Tutor] Question on dictionary

2014-09-12 Thread Sunil Tech
Hi All, i have a dictionary like res = [{'description': 'Testo', 'id': '676', 'parentOf': True}, {'description': 'Pesto', 'id': '620', 'parentOf': False}] i looking for the result like this res = [{'description': 'Testo', 'id': '676', 'id_desc':'676_Testo', 'parentOf': True},

Re: [Tutor] Question on dictionary

2014-09-12 Thread Danny Yoo
i wrote a code like this for i in res: dict = {} dict['id_desc'] = str(i['id'])+','+str(i['description']) i.update(dict) is there any other simple methods to achieve this? Can you avoid the intermediate dict and just assign to i['id_desc'] directly?

Re: [Tutor] Question on dictionary

2014-09-12 Thread Joel Goldstick
On Fri, Sep 12, 2014 at 12:04 PM, Danny Yoo d...@hashcollision.org wrote: i wrote a code like this for i in res: dict = {} dict['id_desc'] = str(i['id'])+','+str(i['description']) A minor revision for the right side of above: ,.join(str(i['id'], str(i['description']))

Re: [Tutor] Question on dictionary

2014-09-12 Thread Sunil Tech
Thank you Danny and Joel :) On Fri, Sep 12, 2014 at 9:51 PM, Joel Goldstick joel.goldst...@gmail.com wrote: On Fri, Sep 12, 2014 at 12:04 PM, Danny Yoo d...@hashcollision.org wrote: i wrote a code like this for i in res: dict = {} dict['id_desc'] =

Re: [Tutor] Question on dictionary

2014-09-12 Thread Steven D'Aprano
On Fri, Sep 12, 2014 at 08:26:29PM +0530, Sunil Tech wrote: Hi All, i have a dictionary like res = [{'description': 'Testo', 'id': '676', 'parentOf': True}, {'description': 'Pesto', 'id': '620', 'parentOf': False}] That is not a dictionary. It is a list containing two dictionaries.

Re: [Tutor] Question about if functions

2014-08-22 Thread Steven D'Aprano
On Fri, Aug 22, 2014 at 02:43:20AM +, Mimi Ou Yang wrote: if (name and age == jimmy and 35): print (BLABLABLABLABLABLAB) if name == 'jimmy' and age == 35: print(BLAB) or if you prefer: if (name, age) == (jimmy, 35): print(BLAB) Take careful note that strings like jimmy have

[Tutor] Question

2014-08-21 Thread Lucia Stockdale
Hi everyone, I have been writing a program to print words backwards until an an empty line of input is entered, but after I put in the input it comes up with TypeError. This is my goal: Line: hello world olleh dlrow Line: extra artxe Line: i love python i evol nohtyp Line: This is my current

Re: [Tutor] Question

2014-08-21 Thread Peter Otten
Lucia Stockdale wrote: Hi everyone, I have been writing a program to print words backwards until an an empty line of input is entered, but after I put in the input it comes up with TypeError. In the future please include the traceback (cut and paste, don't rephrase). This is my goal:

Re: [Tutor] Question

2014-08-21 Thread Felix Dietrich
Lucia Stockdale lucia.stockd...@mggs.vic.edu.au writes: I have been writing a program to print words backwards until an an empty line of input is entered, but after I put in the input it comes up with TypeError. For completeness give us the whole Traceback, it makes pin-pointing the error

Re: [Tutor] Question

2014-08-21 Thread Cameron Simpson
On 21Aug2014 13:03, Lucia Stockdale lucia.stockd...@mggs.vic.edu.au wrote: I have been writing a program to print words backwards until an an empty line of input is entered, but after I put in the input it comes up with TypeError. Hi Lucia, It would be helpful to include the whole traceback

Re: [Tutor] Question

2014-08-21 Thread Peter Otten
Peter Otten wrote: I see another problem, the while loop will run at most once, but you should be able to fix that yourself. Sorry, it will run forever reversing and unreversing the same string... ___ Tutor maillist - Tutor@python.org To

Re: [Tutor] Question

2014-08-21 Thread Dave Angel
Lucia Stockdale lucia.stockd...@mggs.vic.edu.au Wrote in message: Hi everyone, Welcome to the list. And thanks for using text mode. What's the Python version and os version. I expect this is crucial. I have been writing a program to print words backwards until an an empty line of input

[Tutor] Question about if functions

2014-08-21 Thread Mimi Ou Yang
name = input(Enter your name: ) age = input(Enter your age: ) age = int(age) if (name and age == jimmy and 35): print (BLABLABLABLABLABLAB) how can I make a code that has the same effect has the code that I wrote even though it isn’t a real working code. I hope you

Re: [Tutor] Question about if functions

2014-08-21 Thread Alan Gauld
On 22/08/14 03:43, Mimi Ou Yang wrote: name = input(Enter your name: ) age = input(Enter your age: ) age = int(age) if (name and age == jimmy and 35): print (BLABLABLABLABLABLAB) There are two problems here. First You need to put quote signs around 'jimmy' since its a literal string,

Re: [Tutor] Question about style

2014-07-17 Thread Jose Amoreira
Hello, On 07/17/2014 12:05 AM, Alan Gauld wrote: Just throwing this idea in without really thinking about it... Would itertools.groupby work? It takes a sorted collection and groups the items found based on a key function. If the key function deemed two items identical if they were within

Re: [Tutor] Question about style

2014-07-17 Thread Mark Lawrence
On 17/07/2014 17:23, Jose Amoreira wrote: Hello, On 07/17/2014 12:05 AM, Alan Gauld wrote: Just throwing this idea in without really thinking about it... Would itertools.groupby work? It takes a sorted collection and groups the items found based on a key function. If the key function deemed

[Tutor] Question about style

2014-07-16 Thread Jose Amoreira
Hello I wrote a function that, given a list of numbers, finds clusters of values by proximity and returns a reduced list containing the centers of these clusters. However, I find it rather unclear. I would appreciate any comments on how pythonic my function is and suggestions to improve its

Re: [Tutor] Question about style

2014-07-16 Thread Jose Amoreira
Hi! On 07/16/2014 10:14 PM, Wolfgang Maier wrote: careful here: you just stored a tuple instead of a list; doesn't matter for your current implementation, but may bite you at some point. Oh, you're right. Silly mistake, even if harmless for the application I have in mind. else:

Re: [Tutor] Question about style

2014-07-16 Thread Alan Gauld
On 16/07/14 12:49, Jose Amoreira wrote: Hello I wrote a function that, given a list of numbers, finds clusters of values by proximity and returns a reduced list containing the centers of these clusters. However, I find it rather unclear. I would appreciate any comments on how pythonic my

Re: [Tutor] Question about style

2014-07-16 Thread Wolfgang Maier
On 16.07.2014 13:49, Jose Amoreira wrote: Hello I wrote a function that, given a list of numbers, finds clusters of values by proximity and returns a reduced list containing the centers of these clusters. However, I find it rather unclear. I would appreciate any comments on how pythonic my

Re: [Tutor] Question about scraping

2014-05-31 Thread Joel Goldstick
On May 30, 2014 10:12 PM, Matthew Ngaha chigga...@gmail.com wrote: Thanks for the response Alan. I forgot to reply to tutor on my 2nd comment. Just incase someone might want to see it, here it is: Okay I think learning how to scrap (library or framework) is not worth the trouble. Especially

[Tutor] Question about scraping

2014-05-30 Thread Matthew Ngaha
Hey all. I've been meaning to get into web scraping and was pointed to the directions of lxml (library) and scrapy (framework). Can I ask in terms of web scraping, what's the difference between a library and a framework? Surely everyone should use a framework but I get the idea more people use the

Re: [Tutor] Question about scraping

2014-05-30 Thread Alan Gauld
On 30/05/14 18:25, Matthew Ngaha wrote: Hey all. I've been meaning to get into web scraping and was pointed to the directions of lxml (library) and scrapy (framework). Can I ask in terms of web scraping, what's the difference between a library and a framework? I don;t know of anything web

Re: [Tutor] Question about scraping

2014-05-30 Thread ALAN GAULD
On Fri, May 30, 2014 at 7:20 PM, Alan Gauld alan.ga...@btinternet.com wrote: If a site offers an API that returns the data you need then use it, If not you have few alternatives to scraping (although scraping may be 'illegal' anyway due to the impact on other users). But scraping, whether a

Re: [Tutor] Question about scraping

2014-05-30 Thread Matthew Ngaha
Thanks for the response Alan. I forgot to reply to tutor on my 2nd comment. Just incase someone might want to see it, here it is: Okay I think learning how to scrap (library or framework) is not worth the trouble. Especially if some people consider it illegal. Thanks for the input.

Re: [Tutor] Question about O(N**2)

2014-05-04 Thread Devin Jeanpierre
On Sat, May 3, 2014 at 9:13 PM, Steven D'Aprano st...@pearwood.info wrote: On Sat, May 03, 2014 at 03:59:40PM -0700, Danny Yoo wrote: Following up on this. Let's make sure that we're talking about the same thing. The assertion is that the following: fullPath += [...]

[Tutor] Question about O(N**2)

2014-05-03 Thread David Rock
The the Logical Error question, this was brought up: The big problem is this:

Re: [Tutor] Question about O(N**2)

2014-05-03 Thread Danny Yoo
Following up on this. Let's make sure that we're talking about the same thing. The assertion is that the following: fullPath += [...] where fullPath is a list of strings, exhibits O(n^2) time. I don't think this is true. Semantically, the statement above should be equivalent to:

Re: [Tutor] Question about O(N**2)

2014-05-03 Thread Steven D'Aprano
On Sat, May 03, 2014 at 03:59:40PM -0700, Danny Yoo wrote: Following up on this. Let's make sure that we're talking about the same thing. The assertion is that the following: fullPath += [...] where fullPath is a list of strings, exhibits O(n^2) time. I don't think this is

[Tutor] Question regarding Python loops

2014-04-10 Thread Conner Crowe
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 students that left at or before minute

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 students

Re: [Tutor] Question regarding Python loops

2014-04-10 Thread Alan Gauld
On 10/04/14 03:04, Conner Crowe wrote: *Problem 2.* # Here's one possible stand-in: def leave(minute): if minute 0: return minute return 0 So far for this i have: *def* *leave*(minute): *if* minute 0: *return* minute *elif* minute=0: *return* 0 Ignoring the

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

2014-04-09 Thread Jared Nielsen
Thank Danny, That's much more clear. But I still don't understand what's happening with: if line.strip() Is that stripping the line of white space at the same time that it is testing it? On Tue, Apr 8, 2014 at 3:44 PM, Danny Yoo d...@hashcollision.org wrote: Could someone explain why and

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

2014-04-09 Thread Jared Nielsen
Thanks Danny! That was an awesome explanation. On Tue, Apr 8, 2014 at 7:05 PM, Danny Yoo d...@hashcollision.org wrote: if line.strip() Is that stripping the line of white space at the same time that it is testing it? Two features about Python: 1. Strings are immutable, so the above

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 had a very long file

[Tutor] question about strip() and list comprehension

2014-04-08 Thread Jared Nielsen
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 had a very long file of strings filled with blank lines I wanted to remove. I did some Googling and found the above

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

2014-04-08 Thread Danny Yoo
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) Hi Jared, Let me rewrite this without the list comprehension, while preserving behavior. ##

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

2014-04-08 Thread Walter Prins
Hi, On 8 April 2014 22:38, Jared Nielsen nielsen.ja...@gmail.com 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 had a very long file of strings filled

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

2014-04-08 Thread Ben Finney
Jared Nielsen nielsen.ja...@gmail.com writes: I had a very long file of strings filled with blank lines I wanted to remove. I did some Googling and found the above code snippet The code you found is one of several syntactic shortcuts in Python, which allow creating a sequence directly from an

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

2014-04-08 Thread Steven D'Aprano
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 had a very long file of strings filled with

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

2014-04-08 Thread Danny Yoo
if line.strip() Is that stripping the line of white space at the same time that it is testing it? Two features about Python: 1. Strings are immutable, so the above is computing what a whitespace-stripped line would look like. So that means that 'line.strip()' is doing just a

Re: [Tutor] Question about equality of sets

2014-04-06 Thread spir
On 04/05/2014 07:46 PM, Jim Byrnes wrote: Ubuntu 12.04 python 3.3 I was working through an exercise about sets. I needed to find the duplicates in a list and put them in a set. I figured the solution had to do with sets not supporting duplicates. I finally figured it out but along the way I

[Tutor] Question about equality of sets

2014-04-05 Thread Jim Byrnes
Ubuntu 12.04 python 3.3 I was working through an exercise about sets. I needed to find the duplicates in a list and put them in a set. I figured the solution had to do with sets not supporting duplicates. I finally figured it out but along the way I was experimenting in idle and got some

Re: [Tutor] Question about equality of sets

2014-04-05 Thread Steven D'Aprano
On Sat, Apr 05, 2014 at 12:46:19PM -0500, Jim Byrnes wrote: Ubuntu 12.04 python 3.3 I was working through an exercise about sets. I needed to find the duplicates in a list and put them in a set. I figured the solution had to do with sets not supporting duplicates. I finally figured it

Re: [Tutor] Question about equality of sets

2014-04-05 Thread Jim Byrnes
On 04/05/2014 01:15 PM, Steven D'Aprano wrote: On Sat, Apr 05, 2014 at 12:46:19PM -0500, Jim Byrnes wrote: Ubuntu 12.04 python 3.3 I was working through an exercise about sets. I needed to find the duplicates in a list and put them in a set. I figured the solution had to do with sets not

[Tutor] Question on os.popen

2014-01-19 Thread SM
Hello, I am using os.popen repeatedly to run Unix shell commands within my Python program. To be more specific, I am running in a loop which could iterate as many times as there are lines in an input file - in this example, close to 150 iterations. Each loop has two calls to os.popen. It works

Re: [Tutor] Question on os.popen

2014-01-19 Thread Alan Gauld
On 19/01/14 23:36, SM wrote: I read about os.popen in http://docs.python.org/2/library/subprocess.html#subprocess.Popen This doesn't answer the question but I'm curious. If you read about os.popen in the subprocess module docs why did you use it? The subprocess module replaces all the

Re: [Tutor] Question on os.popen

2014-01-19 Thread SM
Hi Alan, Thanks for your reply. My answer to why I am using os.popen could be a lame one - I have used it extensively in various places before and it has been working well and so was hung up on using it. Now I replaced it by subprocess.check_output with appropriate parameters and it seems to be

Re: [Tutor] Question on os.popen

2014-01-19 Thread eryksun
On Sun, Jan 19, 2014 at 6:36 PM, SM sunith...@gmail.com wrote: This time it probably ran for a few more iterations than before and stopped with the same error message. This time it also output the following messages: IOError: [Errno 4] Interrupted system call Attribute not found in file

Re: [Tutor] Question on os.popen

2014-01-19 Thread Dave Angel
SM sunith...@gmail.com Wrote in message: Sorry for not giving details on the OS and python version I am using: Ubuntu and Python3 On Sun, Jan 19, 2014 at 8:20 PM, Alan Gauld ala n.ga...@btinternet.com wrote: On 19/01/14 23:36, SM wrote: I read about os.popen in

Re: [Tutor] Question on os.popen

2014-01-19 Thread SM
Eryksun: Thanks for your reply. Yes, as I mentioned in my reply to Allen, I used subprocess.check_output and it worked for me. -SM On Sun, Jan 19, 2014 at 11:33 PM, eryksun eryk...@gmail.com wrote: On Sun, Jan 19, 2014 at 6:36 PM, SM sunith...@gmail.com wrote: This time it probably ran for

Re: [Tutor] Question on os.popen

2014-01-19 Thread SM
In the upper left corner of that page is a dropdown you can use to get to 3.3 for example. Thanks for that info. On Sun, Jan 19, 2014 at 11:42 PM, Dave Angel da...@davea.name wrote: SM sunith...@gmail.com Wrote in message: Sorry for not giving details on the OS and python version I am

[Tutor] Question in regards to my assignment

2014-01-18 Thread Jackie Canales
I have with my assignment. class Score:     'A subclass of the object.'          def __init__(self, init):         'Sets the initial score to the object and sets the number of scores that have contributed to the total to 1.'         self.x = 1         self.init = int(init)         self.total =

Re: [Tutor] Question in regards to my assignment

2014-01-18 Thread Alan Gauld
On 18/01/14 22:52, Jackie Canales wrote: def processScores(filename): infile = open(filename, 'r') line = infile.readlines() infile.close() lineNum = 0 s = Score(0) for item in line2: lineNum += 1 What is line2? I assume you mean line? You could do

Re: [Tutor] Question about subprocess

2014-01-11 Thread eryksun
On Sat, Jan 11, 2014 at 12:46 AM, Danny Yoo d...@hashcollision.org wrote: There is a warning in the documentation on subprocess that might be relevant to your situation: Warning: Use communicate() rather than .stdin.write, .stdout.read or .stderr.read to avoid deadlocks due to any of

Re: [Tutor] Question about subprocess

2014-01-11 Thread eryksun
On Sat, Jan 11, 2014 at 12:51 AM, Steven D'Aprano st...@pearwood.info wrote: However, when I writed it into a .py file and execute the .py file, it blocked at temp=p.readline(). Of course it does. You haven't actually called the .exe file, all you have done is created a Popen instance and

Re: [Tutor] Question about subprocess

2014-01-11 Thread eryksun
On Fri, Jan 10, 2014 at 11:48 PM, daedae11 daeda...@126.com wrote: p = subprocess.Popen(['E:/EntTools/360EntSignHelper.exe', 'E:/build/temp/RemoteAssistSetup.exe'], stdout=subprocess.PIPE, shell=True).stdout Is 360EntSignHelper supposed to run RemoteAssistSetup as a

Re: [Tutor] Question about subprocess

2014-01-11 Thread Steven D'Aprano
On Sat, Jan 11, 2014 at 04:26:00AM -0500, eryksun wrote: On Sat, Jan 11, 2014 at 12:51 AM, Steven D'Aprano st...@pearwood.info wrote: However, when I writed it into a .py file and execute the .py file, it blocked at temp=p.readline(). Of course it does. You haven't actually called the

[Tutor] Question about subprocess

2014-01-10 Thread daedae11
p = subprocess.Popen(['E:/EntTools/360EntSignHelper.exe', 'E:/build/temp/RemoteAssistSetup.exe'], stdout=subprocess.PIPE, shell=True).stdout temp = p.readline(); print temp p.close() When I run the above code in command line, it works formally. However, when I writed it

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