On Mon, Oct 22, 2012 at 8:54 PM, Steven D'Aprano wrote:
>> Recently I've become a fan of executable packages. In __main__.py,
>> it's always the right thing to do.
>
>
> I would disagree there too. I think that unconditionally running main
> is the wrong thing to do, except perhaps in the most tri
On 23/10/12 11:25, Devin Jeanpierre wrote:
On Mon, Oct 22, 2012 at 6:15 PM, Steven D'Aprano wrote:
Not that. That unconditionally executes main the first time you access
the module, *regardless* of whether it is being run as a script or
being imported. That is nearly always the wrong thing to d
On Mon, Oct 22, 2012 at 8:42 PM, Steven D'Aprano wrote:
> If you do that, and the module directly or indirectly imports itself
> while it is running as a script, you may run into trouble. But writing
> a dual-purpose module that is usable as an importable module or as a
> stand-alone script is not
On 23 October 2012 01:43, Steven D'Aprano wrote:
> In general, your __iter__ method will be trivially simple:
>
> def __iter__(self):
> return self
>
> and most of the logic will be in __next__. I see your __iter__
> method is a little more complicated, but I haven't studied it
> in detail to
On 22/10/12 21:52, eryksun wrote:
On Mon, Oct 22, 2012 at 6:37 AM, Steven D'Aprano wrote:
On 22/10/12 21:21, Saad Javed wrote:
for x, y , z in zip(a, b, c):
L.extend([x, y, z])
print L
This is not your code, because that gives a SyntaxError. Where is
the indentation? Indentation is required
On 23/10/12 09:30, Bryan A. Zimmer wrote:
I know there are errors in the program, but I wanted to see if someone
can tell me something about the iterator "magic" that this program is
trying to use.
In simple terms: an iterator is a sequence of items that understands
the iterator protocol. If y
On 22/10/12 22:54, Devin Jeanpierre wrote:
On Mon, Oct 22, 2012 at 7:45 AM, Matthew Ngaha wrote:
the 2nd one usually includes a lot more code then i showed. can you please
tell me why different methods are used to access the main code? is it just
preference or is one way actually better coding
On Mon, Oct 22, 2012 at 9:23 AM, Walter Prins wrote:
> Devin,
>
> On 22 October 2012 12:54, Devin Jeanpierre wrote:
>> On Mon, Oct 22, 2012 at 7:45 AM, Matthew Ngaha wrote:
>>> the 2nd one usually includes a lot more code then i showed. can you please
>>> tell me why different methods are used t
On Mon, Oct 22, 2012 at 6:15 PM, Steven D'Aprano wrote:
> Not that. That unconditionally executes main the first time you access
> the module, *regardless* of whether it is being run as a script or
> being imported. That is nearly always the wrong thing to do.
Recently I've become a fan of execut
On 23/10/12 00:32, Prasad, Ramit wrote:
Most of Ramit's comments are valid, this is just a couple of additional
notes.
from Tkinter import *
This is a frowned upon import style as it can easily override existing
names. Instead use:
import Tkinter as tk # You can change "tk" to something else
Bryan A. Zimmer wrote:
> Hello, all.
>
>
> I am a long-time programmer with little experience in Python, but am
> trying to learn. The example program, attached, is a toy app with a
> GUI that merely prints out environment keys and their associated
> values.
>
> I know there are errors in the pr
Hello, all.
I am a long-time programmer with little experience in Python, but am
trying to learn. The example program, attached, is a toy app with a
GUI that merely prints out environment keys and their associated
values.
I know there are errors in the program, but I wanted to see if someone
can
On 22/10/12 22:45, Matthew Ngaha wrote:
In many of the tutorial examples ive come across, the main code's program
is never at the top level, but always in a function of some sort. i
understand why but, there is always a different way used to access the main
code, i want to know which is the best.
Dewhirst, Rob wrote:
> Thanks Matt and Lazlo. I knew I must have been missing some counter
> not being reset. Both of those options work fine.
>
> You want to do ifile.seek(0) not reader.seek(0) at least from my testing.
>
>
> On Mon, Oct 22, 2012 at 2:27 PM, Matt Williams wrote:
[snip]
Ple
On 22 October 2012 20:57, Daniel Gulko wrote:
> Hi Python Tutor,
Hi Daniel,
> I have an issue trying to figure out how to print out final answers using
> sort and join functions.
Do you know how to use sort and join to print a list of strings in
alphabetical order?
>
> Assignment Specification
On 10/22/2012 03:57 PM, Daniel Gulko wrote:
> Hi Python Tutor,
>
> I have an issue trying to figure out how to print out final answers using
> sort and join functions.
>
> Assignment Specification:
> make a function that is a magic eight ball emulator. emulator will be a
> function that returns o
Hi Python Tutor,
I have an issue trying to figure out how to print out final answers using sort
and join functions.
Assignment Specification:
make a function that is a magic eight ball emulator. emulator will be a
function that returns one of the possible answers. Make another function that
r
On Mon, Oct 22, 2012 at 3:35 PM, Dewhirst, Rob wrote:
>
>> import csv
>> ifile = open('test.csv', "r")
>> reader = csv.reader(ifile)
>> inData = []
>> for row in reader:
>> inData.append[row]
>> ifile.close()
>>
>> you can now loop through inData to your heart's desire.
Alternatively:
On Mon, Oct 22, 2012 at 3:35 PM, Dewhirst, Rob wrote:
> Thanks Matt and Lazlo. I knew I must have been missing some counter
> not being reset. Both of those options work fine.
>
> You want to do ifile.seek(0) not reader.seek(0) at least from my testing.
>
>
> On Mon, Oct 22, 2012 at 2:27 PM, Mat
Hello Ramit
yes solution worked...
thanks and regards
marco
On Mon, Oct 22, 2012 at 5:58 PM, Prasad, Ramit wrote:
> Marco Mistroni wrote:
>
> > Hello
> > i found the problem. It's calling self.list.ClearAll that causes the
> segmentation fault.
> > removing the call to ClearAll fixed my pro
On Mon, Oct 22, 2012 at 3:28 PM, LZAntal wrote:
> On Oct 22, 2012, at 12:20 PM, "Dewhirst, Rob" wrote:
>
>> import csv
>> ifile = open('test.csv', "r")
>> reader = csv.reader(ifile)
>
> I believe csv module uses iterator so you need to run reader.seek(0) between
> the for loops
You have to rese
Thanks Matt and Lazlo. I knew I must have been missing some counter
not being reset. Both of those options work fine.
You want to do ifile.seek(0) not reader.seek(0) at least from my testing.
On Mon, Oct 22, 2012 at 2:27 PM, Matt Williams wrote:
> Dear Rob,
>
> This caught me out as well for
On Mon, Oct 22, 2012 at 3:20 PM, Dewhirst, Rob wrote:
> import csv
> ifile = open('test.csv', "r")
> reader = csv.reader(ifile)
> for row in reader:
> print row
> for row in reader:
> print row
> ifile.close()
>
> This is a simplified version of what I am trying to do - loop throug
Dewhirst, Rob wrote:
import csv
ifile = open('test.csv', "r")
reader = csv.reader(ifile)
for row in reader:
print row
for row in reader:
print row
ifile.close()
This is a simplified version of what I am trying to do - loop through
a CSV file twice. Why does the second for loop n
Hi,
On Oct 22, 2012, at 12:20 PM, "Dewhirst, Rob" wrote:
> import csv
> ifile = open('test.csv', "r")
> reader = csv.reader(ifile)
> for row in reader:
> print row
> for row in reader:
> print row
> ifile.close()
>
> This is a simplified version of what I am trying to do - loop thro
import csv
ifile = open('test.csv', "r")
reader = csv.reader(ifile)
for row in reader:
print row
for row in reader:
print row
ifile.close()
This is a simplified version of what I am trying to do - loop through
a CSV file twice. Why does the second for loop not execute at all?
The
On Mon, Oct 22, 2012 at 2:26 PM, Oscar Benjamin
wrote:
>
> They both import each other. That is a circular import and it can
> create problems. My advice for this issue is not "avoid importable
> scripts" but rather "avoid circular imports" (a good idea anyway).
I agree it's better to refactor co
On 22 October 2012 16:14, eryksun wrote:
> On Mon, Oct 22, 2012 at 9:35 AM, Oscar Benjamin
> wrote:
>>
>> It is also sometimes useful to define a number of scripts that are in
>> the same directory but share some code by importing one another. You
>> need the if __name__ =="__main__" block for th
Mike McTernan wrote:
Hi there,
I am doing some online tutorials and have found two approaches to
naming things: this_is_a_name and thisIsAName.
Which one is the best practice for Python? I am a totally newbie to
programming and want to make sure I start with the most common
approach.
The off
On Mon, Oct 22, 2012 at 1:43 PM, Mike McTernan wrote:
> Hi there,
>
> I am doing some online tutorials and have found two approaches to
> naming things: this_is_a_name and thisIsAName.
Read PEP 8, specifically the section on Naming Conventions:
http://www.python.org/dev/peps/pep-0008/#naming-con
Hi there,
I am doing some online tutorials and have found two approaches to
naming things: this_is_a_name and thisIsAName.
Which one is the best practice for Python? I am a totally newbie to
programming and want to make sure I start with the most common
approach.
Thanks,
mike
___
Marco Mistroni wrote:
> Hello
> i found the problem. It's calling self.list.ClearAll that causes the
> segmentation fault.
> removing the call to ClearAll fixed my problem , but i still want to clear
> the list before i load new
> data..
> could anyone assist?
I think the problem is th
On Mon, Oct 22, 2012 at 11:14 AM, eryksun wrote:
>
> Just to clarify that I'm following you, would you count the following
> as a script importing itself 'indirectly'?
>
> Assume two modules in the same directory, mod1.py and mod2.py, can
> both act as the main entry point, and both import each ot
On Mon, Oct 22, 2012 at 9:35 AM, Oscar Benjamin
wrote:
>
> It is also sometimes useful to define a number of scripts that are in
> the same directory but share some code by importing one another. You
> need the if __name__ =="__main__" block for this.
>
> The problem that Devin is referring to onl
On 22 October 2012 12:54, Devin Jeanpierre wrote:
> On Mon, Oct 22, 2012 at 7:45 AM, Matthew Ngaha wrote:
Hi Devin, your context was missing the crucial part showing the "2nd one":
>> they call the main program by simply calling the main function. I've also
>> seen a more complcated:
>>
>> if _
Devin,
On 22 October 2012 12:54, Devin Jeanpierre wrote:
> On Mon, Oct 22, 2012 at 7:45 AM, Matthew Ngaha wrote:
>> the 2nd one usually includes a lot more code then i showed. can you please
>> tell me why different methods are used to access the main code? is it just
>> preference or is one way
On Mon, Oct 22, 2012 at 7:54 AM, Devin Jeanpierre
wrote:
>
> The second one is used if your importable modules are also scripts
> that can be executed.
>
> That's a bad idea, because it results in the same source file being
> executed twice, producing distinct classes that break typechecking.
Her
oh ok i understand it.. Thanks for the help guys
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
On Mon, Oct 22, 2012 at 7:45 AM, Matthew Ngaha wrote:
> In many of the tutorial examples ive come across, the main code's program is
> never at the top level, but always in a function of some sort. i understand
> why but, there is always a different way used to access the main code, i
> want to kn
On 22/10/2012 12:45, Matthew Ngaha wrote:
In many of the tutorial examples ive come across, the main code's program
is never at the top level, but always in a function of some sort. i
understand why but, there is always a different way used to access the main
code, i want to know which is the bes
On Mon, Oct 22, 2012 at 7:45 AM, Matthew Ngaha wrote:
> the 2nd one usually includes a lot more code then i showed. can you please
> tell me why different methods are used to access the main code? is it just
> preference or is one way actually better coding practice?
The second one is used if you
In many of the tutorial examples ive come across, the main code's program
is never at the top level, but always in a function of some sort. i
understand why but, there is always a different way used to access the main
code, i want to know which is the best.
main()
main's code
#top level
mai
Hi Saad,
On 22 October 2012 11:37, Steven D'Aprano wrote:
> On 22/10/12 21:21, Saad Javed wrote:
>> I'm trying to create a list (L) from items of different lists (a, b, c)
>> but
>> in a specific order (L = [[a1, b1, c1], [a2, b2, c2]...etc])
>> L = []
>> a = [1, 2, 3, 4]
>> b = ['a', 'b', 'c', '
On Mon, Oct 22, 2012 at 6:37 AM, Steven D'Aprano wrote:
> On 22/10/12 21:21, Saad Javed wrote:
>>
>> for x, y , z in zip(a, b, c):
>> L.extend([x, y, z])
>> print L
>
> This is not your code, because that gives a SyntaxError. Where is
> the indentation? Indentation is required in Python, if you le
On 22/10/12 21:21, Saad Javed wrote:
Hi,
I'm trying to create a list (L) from items of different lists (a, b, c) but
in a specific order (L = [[a1, b1, c1], [a2, b2, c2]...etc])
L = []
a = [1, 2, 3, 4]
b = ['a', 'b', 'c', 'd']
c = [2009, 2010, 2011, 2012]
for x, y , z in zip(a, b, c):
L.extend(
Hi Saad,
On 22 October 2012 11:21, Saad Javed wrote:
> Hi,
>
> I'm trying to create a list (L) from items of different lists (a, b, c) but
> in a specific order (L = [[a1, b1, c1], [a2, b2, c2]...etc])
> L = []
> a = [1, 2, 3, 4]
> b = ['a', 'b', 'c', 'd']
> c = [2009, 2010, 2011, 2012]
>
> for x
Hi,
I'm trying to create a list (L) from items of different lists (a, b, c) but
in a specific order (L = [[a1, b1, c1], [a2, b2, c2]...etc])
L = []
a = [1, 2, 3, 4]
b = ['a', 'b', 'c', 'd']
c = [2009, 2010, 2011, 2012]
for x, y , z in zip(a, b, c):
L.extend([x, y, z])
print L
But this outputs:
[
l.extend does work. Thanks!
On Monday, October 22, 2012, Saad Javed wrote:
> My program downloads multiple entry values from the net. I'm trying to
> combine them in a list in a particular sequence.
>
> l = []
> feed1 = urllib2.urlopen(rssPage1)
> tree1 = etree.parse(feed1)
> x = tree1.xpath("/rs
48 matches
Mail list logo