[Tutor] Performing an union of two files containing keywords

2014-02-17 Thread Aaron Misquith
I have 2 different text files. File1.txt contains: file RAMPython parser File2.txt contains: file1234 program I want to perform an union of these both files such that i get an output file3.txt which contains: file RAMPython parser1234 program The program that i'm working on just combines

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

2014-02-17 Thread Mark Lawrence
On 17/02/2014 09:07, Aaron Misquith wrote: I have 2 different text files. File1.txt contains: |file RAM Python parser| File2.txt contains: |file 1234 program| I want to perform an union of these both files such that i get an output file3.txt which contains: |file RAM Python parser 1234

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

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

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

2014-02-17 Thread spir
On 02/17/2014 10:07 AM, Aaron Misquith wrote: I have 2 different text files. File1.txt contains: file RAMPython parser File2.txt contains: file1234 program I want to perform an union of these both files such that i get an output file3.txt which contains: file RAMPython parser1234 program

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

2014-02-17 Thread Oscar Benjamin
On 17 February 2014 09:07, Aaron Misquith aaronmisqu...@gmail.com wrote: The program that i'm working on just combines two files. Any help on performing an union such that a keyword would not be repeated would be appreciated. Code: with open(C:\\File1.txt) as fin1: lines = fin1.readlines()

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

2014-02-17 Thread Alan Gauld
On 17/02/14 10:29, spir wrote: I want to perform an union of these both files such that i get an output file3.txt which contains: file RAMPython parser1234 program I don't understand the logic of your union (???) at all. Is your example correct? It's an email formatting issue, I saw the

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

2014-02-17 Thread Dave Angel
On 02/17/2014 06:12 AM, Oscar Benjamin wrote: On 17 February 2014 09:07, Aaron Misquith aaronmisqu...@gmail.com wrote: The program that i'm working on just combines two files. Any help on performing an union such that a keyword would not be repeated would be appreciated. Code: with

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

2014-02-17 Thread Dave Angel
Aaron Misquith aaronmisqu...@gmail.com Wrote in message: As two others have said, a set is the simplest solution to avoid duplicates. There are other questions to ask, however. Primary is whether order matters. If it does not, then observe that list(set(mylist)) will produce a list from a

[Tutor] Regarding Exceptions

2014-02-17 Thread Khalid Al-Ghamdi
Hi, in the following snippet, why is it I don't need to create an Exception object and I can use the class directly in raise my custom exception? iframe src=http://pastebin.com/embed_iframe.php?i=7ANcvLHR; style=border:none;width:100%/iframe Thanks ___

[Tutor] Regarding Exceptions

2014-02-17 Thread Khalid Al-Ghamdi
Hi, Why is it i can use mu custom class exception without creating an exception object first? Thanks 1. class ShortInputException(Exception): def __init__(self, length, atleast): 2. Exception.__init__(self) 3. self.length = length 4. self.atleast =

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

2014-02-17 Thread Dave Angel
On 02/17/2014 05:29 AM, spir wrote: On 02/17/2014 10:07 AM, Aaron Misquith wrote: I have 2 different text files. File1.txt contains: file RAMPython parser File2.txt contains: file1234 program I want to perform an union of these both files such that i get an output file3.txt which contains:

[Tutor] Beginner - Clarifying 'understanding randint arguments'

2014-02-17 Thread Marc Eymard
Hi Tutor, The previous elements I sent to the mailing list were incomplete and needs no answer from Tutor. To clarify and re-phrase my script issue: I want to code a game whereby the computer guesses either by luck or deduction a number I pick within [0, 100]. In attached

Re: [Tutor] Regarding Exceptions

2014-02-17 Thread Chris “Kwpolska” Warrick
On Mon, Feb 17, 2014 at 12:44 PM, Khalid Al-Ghamdi emailkg...@gmail.com wrote: Hi, Why is it i can use mu custom class exception without creating an exception object first? Thanks class ShortInputException(Exception): def __init__(self, length, atleast): Exception.__init__(self)

Re: [Tutor] Upload a file using python

2014-02-17 Thread rakesh sharma
Greetings!! Hi Alan, The error code was that of success. 200.Donno if the site supports a post method. It doesn't but is there any other way of automating the process.The issue of chrome 32 with selenium webdriver has stalled the show for me. Hence i had to fend for some other ways.

Re: [Tutor] Regarding Exceptions

2014-02-17 Thread Alan Gauld
On 17/02/14 11:44, Khalid Al-Ghamdi wrote: Why is it i can use mu custom class exception without creating an exception object first? There are formatting problems when I try to copy your code. I've tried to fix them below, apologies if I got it wrong. However you do create an instance when

Re: [Tutor] Beginner - Clarifying 'understanding randint arguments'

2014-02-17 Thread Alan Gauld
On 17/02/14 11:39, Marc Eymard wrote: Hi Tutor, The previous elements I sent to the mailing list were incomplete and needs no answer from Tutor. But you got several nonetheless. Did you read them? If so you will know that calling randint() does not change the two xxx_range variables. It

Re: [Tutor] Upload a file using python

2014-02-17 Thread Alan Gauld
On 17/02/14 14:29, rakesh sharma wrote: Greetings!! Hi Alan, The error code was that of success. 200. Donno if the site supports a post method. It doesn't but is there any other way of automating the process. The issue of chrome 32 with selenium webdriver has stalled the show for me. Hence i

Re: [Tutor] Upload a file using python

2014-02-17 Thread Mark Lawrence
On 17/02/2014 15:38, Alan Gauld wrote: In that case you should be able to call the Ajax API directly using urllib or cgi possibly some higher level Ajax module - I suspect one will exist somewhere! First port of call for such things https://pypi.python.org/pypi -- My fellow Pythonistas, ask

[Tutor] for: how to skip items

2014-02-17 Thread Gabriele Brambilla
Hi, I'm wondering how I can (if I can) make a for loop in which I don't use all the elements. for example a100 = list(range(100)) for a in a100: print(a) it print out to me all the numbers from 0 to 99 But if I want to display only the numbers 0, 9, 19, 29, 39, ...(one every 10

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

2014-02-17 Thread Oscar Benjamin
On 17 February 2014 13:16, Dave Angel da...@davea.name wrote: On 02/17/2014 06:12 AM, Oscar Benjamin wrote: Something like this: with open(r'D:\file3.txt', 'r+') as fout: keywords_seen = set() for filename in r'C:\File1.txt', r'C:\File2.txt': with open(filename) as fin:

Re: [Tutor] for: how to skip items

2014-02-17 Thread Oscar Benjamin
On 17 February 2014 16:05, Gabriele Brambilla gb.gabrielebrambi...@gmail.com wrote: Hi, I'm wondering how I can (if I can) make a for loop in which I don't use all the elements. for example a100 = list(range(100)) for a in a100: print(a) it print out to me all the numbers

Re: [Tutor] for: how to skip items

2014-02-17 Thread Joel Goldstick
On Feb 17, 2014 11:06 AM, Gabriele Brambilla gb.gabrielebrambi...@gmail.com wrote: Hi, I'm wondering how I can (if I can) make a for loop in which I don't use all the elements. for example a100 = list(range(100)) for a in a100: print(a) it print out to me all the numbers

Re: [Tutor] for: how to skip items

2014-02-17 Thread Gabriele Brambilla
Excuse me for the bad english: not a random float numbers but random float numbers Gabriele 2014-02-17 11:13 GMT-05:00 Gabriele Brambilla gb.gabrielebrambi...@gmail.com: No sorry, it's because my problem is not so simple: imagine that in a100 contains not integer sorted in a good way but

Re: [Tutor] for: how to skip items

2014-02-17 Thread David Palao
Hi Gabriele, Without knowing the details of what you are trying, I guess you could be interested in looking at how to define your own iterators. Regards 2014-02-17 17:05 GMT+01:00 Gabriele Brambilla gb.gabrielebrambi...@gmail.com: Hi, I'm wondering how I can (if I can) make a for loop in

Re: [Tutor] for: how to skip items

2014-02-17 Thread Gabriele Brambilla
Doesn't exist a way in Python to do like in C for i=0, i100, i=i+10 ? without creating a list of index? Gabriele 2014-02-17 11:15 GMT-05:00 David Palao dpalao.pyt...@gmail.com: Hi Gabriele, Without knowing the details of what you are trying, I guess you could be interested in looking at

Re: [Tutor] for: how to skip items

2014-02-17 Thread Oscar Benjamin
On 17 February 2014 16:13, Gabriele Brambilla gb.gabrielebrambi...@gmail.com wrote: No sorry, it's because my problem is not so simple: imagine that in a100 contains not integer sorted in a good way but a random float numbers. How could I display only one item every 10? for n, a in

Re: [Tutor] for: how to skip items

2014-02-17 Thread Gabriele Brambilla
No sorry, it's because my problem is not so simple: imagine that in a100 contains not integer sorted in a good way but a random float numbers. How could I display only one item every 10? thanks Gabriele 2014-02-17 11:08 GMT-05:00 Oscar Benjamin oscar.j.benja...@gmail.com: On 17 February

Re: [Tutor] for: how to skip items

2014-02-17 Thread Oscar Benjamin
On 17 February 2014 16:17, Gabriele Brambilla gb.gabrielebrambi...@gmail.com wrote: Doesn't exist a way in Python to do like in C for i=0, i100, i=i+10 ? without creating a list of index? You haven't said which Python version you're using. In Python 2 the range function returns a list but

Re: [Tutor] for: how to skip items

2014-02-17 Thread Gabriele Brambilla
thanks, in the end I'm using something like this and it works: zipPARApha = zip(Pampli, Pgamma, Pecut, Pb, g) for n, (a1,b1,c1,d1,pha) in enumerate(zipPARApha): where the arguments of zip are lists of the same size. Gabriele 2014-02-17 11:19 GMT-05:00 Oscar Benjamin

Re: [Tutor] for: how to skip items

2014-02-17 Thread Mark Lawrence
On 17/02/2014 16:17, Gabriele Brambilla wrote: Doesn't exist a way in Python to do like in C for i=0, i100, i=i+10 ? without creating a list of index? Gabriele 2014-02-17 11:15 GMT-05:00 David Palao dpalao.pyt...@gmail.com mailto:dpalao.pyt...@gmail.com: Hi Gabriele, Without

Re: [Tutor] for: how to skip items

2014-02-17 Thread emile
On 02/17/2014 08:05 AM, Gabriele Brambilla wrote: Hi, I'm wondering how I can (if I can) make a for loop in which I don't use all the elements. for example a100 = list(range(100)) for a in a100: print(a) it print out to me all the numbers from 0 to 99 But if I want to display

[Tutor] Fwd: for: how to skip items

2014-02-17 Thread ugajin
0, 9, 19, 29, 39, is not every 10th index If you want to output every 10th. index try: a100 = list(range(0,100,10)) for a in a100: print(a) -Original Message- From: Gabriele Brambilla gb.gabrielebrambi...@gmail.com To: python tutor tutor@python.org Sent: Mon, 17

Re: [Tutor] for: how to skip items

2014-02-17 Thread Andreas Perstinger
Gabriele Brambilla gb.gabrielebrambi...@gmail.com wrote: it's because my problem is not so simple: imagine that in a100 contains not integer sorted in a good way but a random float numbers. How could I display only one item every 10? You can provide a step size if you slice a list: l =

Re: [Tutor] Regarding Exceptions

2014-02-17 Thread Dave Angel
On 02/17/2014 06:44 AM, Khalid Al-Ghamdi wrote: Hi, Why is it i can use mu custom class exception without creating an exception object first? Thanks 1. class ShortInputException(Exception): def __init__(self, length, atleast): 2. Exception.__init__(self) 3.

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

2014-02-17 Thread Dave Angel
Oscar Benjamin oscar.j.benja...@gmail.com Wrote in message: On 17 February 2014 13:16, Dave Angel da...@davea.name wrote: On 02/17/2014 06:12 AM, Oscar Benjamin wrote: Something like this: with open(r'D:\file3.txt', 'r+') as fout: keywords_seen = set() for filename in

Re: [Tutor] for: how to skip items

2014-02-17 Thread Dave Angel
Gabriele Brambilla gb.gabrielebrambi...@gmail.com Wrote in message: in the end I'm using something like this and it works: zipPARApha = zip(Pampli, Pgamma, Pecut, Pb, g) for n, (a1,b1,c1,d1,pha) in enumerate(zipPARApha): where the arguments of zip are lists of the same size. Simpler

[Tutor] constructing semi-arbitrary functions

2014-02-17 Thread André Walker-Loud walksl...@gmail.com
Hello python tutors, I am utilizing a 3rd party numerical minimization routine. This routine requires an input function, which takes as arguments, only the variables with which to solve for. But I don’t want to define all possible input functions, in a giant switch, but rather, if I know I

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Oscar Benjamin
On Feb 17, 2014 7:24 PM, quot;André Walker-Loud lt;walksl...@gmail.comgt;quot; walksl...@gmail.com wrote: Question 1: Is there a better way to accomplish (my hopefully clear) goals? I'm not sure that there is given the constraints you're under from the third party function. Question 2: In

Re: [Tutor] constructing semi-arbitrary functions

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

Re: [Tutor] when is pythondontwritebytecode useful?

2014-02-17 Thread Ben Finney
Albert-Jan Roskam fo...@yahoo.com writes: I know what it does (http://docs.python.org/2/using/cmdline.html#envvar-PYTHONDONTWRITEBYTECODE), i.e. no pyc or pyo fiules are written, but WHY is that sometimes a good thing? There are numerous reasons why one might not want files to suddenly be

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Oscar Benjamin
On 17 February 2014 20:13, Peter Otten __pete...@web.de wrote: André Walker-Loud walksl...@gmail.com wrote: The 3rd party minimizer utilizes the .func_code.co_varnames and .func_code.co_argcount to determine the name and number of variables to minimize. eg. = METHOD 2: use

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread André Walker-Loud walksl...@gmail.com
Hi Oscar, Let me clear up my description of one point - I don’t want to pick on the third party software guys. The right solution is to change the interface of the third party function. It is poorly designed and should not be inspecting those function attributes or it should at least

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Steven D'Aprano
On Mon, Feb 17, 2014 at 07:58:00PM +, Oscar Benjamin wrote: The right solution is to change the interface of the third party function. It is poorly designed and should not be inspecting those function attributes or it should at least provide an option for you to provide that information

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Dave Angel
Peter Otten __pete...@web.de Wrote in message: André Walker-Loud walksl...@gmail.com wrote: Hello python tutors, I am utilizing a 3rd party numerical minimization routine. This routine requires an input function, which takes as arguments, only the variables with which to solve for.

[Tutor] Assignment, references, binding (was: is an alias a variable)

2014-02-17 Thread Ben Finney
Ian D dux...@hotmail.com writes: is import longModuleName as lmn or lmn = longModuleName creating an alias or assigning to a variable. or both? Assignment and import both bind a name to an object. NAmes are one (common) kind of reference. The only way to get at objects is by

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Oscar Benjamin
On 17 February 2014 21:18, André Walker-Loud walksl...@gmail.com walksl...@gmail.com wrote: What I am trying to avoid is having to write a special case for each order of polynomial I want. I tried the following def poly(x,pars): val = 0. for i,ci in enumerate(pars): val

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread André Walker-Loud walksl...@gmail.com
This particular case is easily solved: def f_lambda(x,pars): return lambda x: poly(x,*pars) You let the closure take care of pars and return a function that takes exactly one argument x. Hi Oscar, This is the opposite of what I am trying to do. In the example, x represents the

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Oscar Benjamin
On 17 February 2014 22:15, André Walker-Loud walksl...@gmail.com walksl...@gmail.com wrote: This particular case is easily solved: def f_lambda(x,pars): return lambda x: poly(x,*pars) You let the closure take care of pars and return a function that takes exactly one argument x. Hi

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Oscar Benjamin
On 17 February 2014 22:15, André Walker-Loud walksl...@gmail.com walksl...@gmail.com wrote: This particular case is easily solved: def f_lambda(x,pars): return lambda x: poly(x,*pars) You let the closure take care of pars and return a function that takes exactly one argument x. Hi

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread André Walker-Loud walksl...@gmail.com
Hi Oscar, On Feb 17, 2014, at 6:02 PM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: On 17 February 2014 22:15, André Walker-Loud walksl...@gmail.com walksl...@gmail.com wrote: This particular case is easily solved: def f_lambda(x,pars): return lambda x: poly(x,*pars) You let the

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread André Walker-Loud walksl...@gmail.com
Hi Oscar, On Feb 17, 2014, at 7:03 PM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: On 17 February 2014 22:15, André Walker-Loud walksl...@gmail.com walksl...@gmail.com wrote: This particular case is easily solved: def f_lambda(x,pars): return lambda x: poly(x,*pars) You let