|
Jonnty posted:There are lots of options, depending on how you're doing things. I've tried both methods (probably incorrectly) and it is still printing off all the lines in the text file. Here is what I have: code:
|
# ? Jul 26, 2010 03:43 |
|
|
# ? Jun 11, 2024 02:36 |
|
Hughmoris posted:You'll need to use enumerate() if you want to do it that way, because "line" isn't the index of the line, it refers to the line itself. Here you are with slicing: code:
|
# ? Jul 26, 2010 03:52 |
|
sund posted:You'll need to use enumerate() if you want to do it that way, because "line" isn't the index of the line, it refers to the line itself. Here you are with slicing: That gives me this error: Traceback (most recent call last): File "C:/Python27/programs/reader.py", line 17, in <module> for line in myMovies[8:]: TypeError: 'file' object is not subscriptable
|
# ? Jul 26, 2010 03:54 |
|
sund posted:You'll need to use enumerate() if you want to do it that way, because "line" isn't the index of the line, it refers to the line itself. Here you are with slicing: You need to use islice or read the whole file into memory with readlines and then slice it: code:
code:
|
# ? Jul 26, 2010 04:09 |
|
sund posted:You'll need to use enumerate() if you want to do it that way, because "line" isn't the index of the line, it refers to the line itself. Here you are with slicing: whoops, I'm thick. Sorry Hughmoris!
|
# ? Jul 26, 2010 04:24 |
|
Jonnty posted:whoops, I'm thick. Sorry Hughmoris! No worries, its the thought that counts! Thanks for input Lonely Wolf, I'll give it a shot when I get off work today. Since you're all so helpful, I have another question. I posted this in the Linux thread but perhaps there is an easier way to do it in Python. I'm working on my first project which is a little script that will gather the names of DVDs being released that week and send those names to me in an email. I have figured out how to pull the names from the website and put them in a text file but I'm a bit clueless on how to automate an email with the names in the body of the message. I have one computer running Linux Mint 8 and another running Windows XP. I have a Gmail address and an email address through my ISP. Any suggestions on how to best tackle the email issue, assuming I have no knowledge beyond using webmail or Outlook. Hughmoris fucked around with this message at 14:25 on Jul 26, 2010 |
# ? Jul 26, 2010 14:13 |
|
Hughmoris posted:No worries, its the thought that counts! Thanks for input Lonely Wolf, I'll give it a shot when I get off work today. Since you're all so helpful, I have another question. I posted this in the Linux thread but perhaps there is an easier way to do it in Python. code:
|
# ? Jul 26, 2010 14:19 |
|
Hughmoris posted:No worries, its the thought that counts! Thanks for input Lonely Wolf, I'll give it a shot when I get off work today. Since you're all so helpful, I have another question. I posted this in the Linux thread but perhaps there is an easier way to do it in Python. on unix, you would make your program print all of the information, and run it under cron cron runs a script at a specified time repeatedly and emails you the result. this would be the 'easiest' way if everything is set up properly.
|
# ? Jul 26, 2010 15:17 |
|
Is there a more abstracted python LDAP library than python-ldap?
|
# ? Jul 26, 2010 17:25 |
|
I have an XML file with say the element <name> and a list of names, some foreign so they have accents and other special characters in them. I wrote a script to read the XML file and find all the elements <name> and write to a file the names as a list. This almost works fine, but the problem is that it breaks when it encounters a name with an accent. The thing is, I don't want to strip the accents away because I want my outputted list (an HTML file) to have them. I've searched for variations of python and unicode and encoding but I can't seem to find any answers. All I want is for my script to either print the accents themselves or convert them into some kind of code that my browser can parse (such as À -> & Agrave;). Any suggestions? Edit: import codecs and declaring my output file utf-8 seemed to do the trick. Ziir fucked around with this message at 20:43 on Jul 26, 2010 |
# ? Jul 26, 2010 18:03 |
|
Can somebody explain how this works to me? Why doesn't it create a new list for the default argument on every call?code:
code:
|
# ? Jul 28, 2010 15:49 |
|
Sweeper posted:Can somebody explain how this works to me? Why doesn't it create a new list for the default argument on every call? I think its due to the way keyword arguments work. When you are supplying a value for a default keyword argument, that value is used for all future calls of the function. Like if you had code:
You probably want something this: code:
tripwire fucked around with this message at 16:13 on Jul 28, 2010 |
# ? Jul 28, 2010 16:10 |
|
tripwire posted:I think its due to the way keyword arguments work. When you are supplying a value for a default keyword argument, that value is used for all future calls of the function. I figured it was something about default arguments only being created one. Is that a design decision? Is there a reason to create them only once vs. creating it every time?
|
# ? Jul 28, 2010 16:27 |
|
Sweeper posted:I figured it was something about default arguments only being created one. Is that a design decision? Is there a reason to create them only once vs. creating it every time? Im pretty sure its designed that way on purpose. I could be wrong but I'd imagine default values sit outside of the function for efficiency- if a default argument had to be created every time a function was invoked, thered be way too much overhead.
|
# ? Jul 28, 2010 16:34 |
|
tripwire posted:Im pretty sure its designed that way on purpose. I could be wrong but I'd imagine default values sit outside of the function for efficiency- if a default argument had to be created every time a function was invoked, thered be way too much overhead. Yep, that's it. Never use a mutable object as a default argument. Another way to do it which is a bit more informative from the function declaration would be code:
|
# ? Jul 28, 2010 16:40 |
|
Stack Overflow has a good overview of the topic tl;dr is that default arguments are properties on a function or method object, and get created at class/function definition. You can even access them via whatever.func_defaults
|
# ? Jul 28, 2010 17:32 |
|
code:
tef fucked around with this message at 17:53 on Jul 28, 2010 |
# ? Jul 28, 2010 17:47 |
|
I figured it was an efficiency thing, just took my by surprise when I saw it
|
# ? Jul 28, 2010 18:22 |
|
Ok, does anyone know how to properly write windows filenames in python 2.7? I've tried target_dir = r"d:/pythonbackup/" but that fucks everything up. I need a detailed explanation because i have been googling this for 20 minutes and all the explanations on the web fail on my machine for some reason. :/ I've also tried double backslashes like "C:\\backup\\" but that just gives out a windows error that it can't find the dir (probably because of the double backslashes) deichkind42 fucked around with this message at 07:54 on Jul 29, 2010 |
# ? Jul 29, 2010 07:33 |
|
deichkind42 posted:Ok, does anyone know how to properly write windows filenames in python 2.7? I recently saw a suggestion on solving this problem from here (it has a long write up on this problem). You do code:
|
# ? Jul 29, 2010 08:31 |
|
I have a list of data and would like to iterate through sequential subsets of it, it looks like this: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and i want: [1,2,3] [2,3,4] [3,4,5] ... [8,9,10] i have this, which im happy with: code:
edit: i realise you can also have code:
|
# ? Jul 29, 2010 15:01 |
|
code:
leterip fucked around with this message at 16:17 on Jul 29, 2010 |
# ? Jul 29, 2010 16:10 |
|
code:
|
# ? Jul 29, 2010 17:43 |
|
tef posted:
Very nice. This is a version that generalizes to any n: code:
|
# ? Jul 29, 2010 18:39 |
I have some software I use for work that depends on Python 2.x, but I want to do some stuff with 3.x for my own personal ends, is there a way I have have both installed concurrently, and choose which one to use?
|
|
# ? Jul 29, 2010 19:12 |
|
oiseaux morts 1994 posted:I have some software I use for work that depends on Python 2.x, but I want to do some stuff with 3.x for my own personal ends, is there a way I have have both installed concurrently, and choose which one to use? On windows you're going to need to set up your path correctly using the environment variables section: http://docs.python.org/using/windows.html On OS X it kind of depends, but I use MacPorts and this stackoverflow post gives kind of an overview (assuming you have MacPorts setup) I haven't developed on linux in awhile, but I always controlled it with putting the right python version in path via a source command.
|
# ? Jul 29, 2010 19:34 |
|
Can someone please tell me how to get Notepad++ to run a python file? I have program.py and even when I hit f5 in Notepad++, all it does is ask me to locate a file (instead of running the file I have open like IDLE), and when I select "program.py" a cmd window just blinks in and out, nothing happens. This is on WinXP.
|
# ? Jul 29, 2010 19:47 |
|
Kire posted:Can someone please tell me how to get Notepad++ to run a python file? -> http://www.daniweb.com/forums/thread151270.html
|
# ? Jul 29, 2010 19:53 |
|
I have a script that I wrote that includes a couple files and modules. The source tree looks like this:code:
Here is my setup.py: code:
|
# ? Jul 30, 2010 07:21 |
|
I have no idea if it works, use pip+virtualenv. pip has an uninstall, plus if that fails (rare) you can always blow away the entire venv.
|
# ? Jul 30, 2010 08:16 |
|
leterip posted:Very nice. This is a version that generalizes to any n: hah cool! thanks very much guys
|
# ? Jul 30, 2010 09:02 |
|
Is there a genericish template system like you'd find in Django in the standard library? What I'm looking to do is: 1) Read in a Key/Value pair text file where not all known keys will be specified. 2) Read in a template file. 3) Write out an instance of the template based on what was read in 1/2 IE: Data: FirstName = Bob Title = Your uncle {% if FirstName %} Hello {{ FirstName }} {% else %} Dear Anonymous {% endif %} (Note I'm using Django's template language just 'cuz that's what I'm thinking of ATM but it doesn't need to look like it as long as it can have conditional blocks.) I'd like to build/deploy the whole thing with IronPython and have it in a large source control project without any external dependences if possible... Is there anything like this?
|
# ? Jul 30, 2010 18:37 |
|
Hughlander posted:Is there a genericish template system like you'd find in Django in the standard library? What I'm looking to do is: Actually, scratch that. The template class in the standard library doesn't do conditional substitution like that. tripwire fucked around with this message at 18:49 on Jul 30, 2010 |
# ? Jul 30, 2010 18:47 |
|
Hughlander posted:Is there a genericish template system like you'd find in Django in the standard library? What I'm looking to do is: I don't think you'll find it in the standard library, but there's this: http://jinja.pocoo.org/2/
|
# ? Jul 30, 2010 18:59 |
|
I googled around and Tempita seems to be on topic at least
|
# ? Jul 30, 2010 19:18 |
|
Lurchington posted:I googled around and Tempita seems to be on topic at least Assuming the docs are correct and it's still just a single 700 line module, I can probably add the 1 file to source control and use it. Thanks!
|
# ? Jul 30, 2010 19:32 |
|
Alright, I have an in-person technical interview for a python development job, and it's my first one ever really (I've been doing project management for the last 6 years). It hasn't been stated, but I think I'd be working with Django and probably relational databases of one kind or another. Those of you who've done a python dev tech interview, were there any good resources that you thought helped prepare you? Or alternatively, anything non-job specific you had to think harder about besides "what are list comprehensions?" I know I'll be whiteboarding something during the interview, and although I'm confident, it'd be silly to not refresh some things. edit: So far, I'm going to be brushing up on multiprocessing vs. threads, along with the Global Interpreter Lock edit2: VVV I've name dropped the big libraries I've used before, so yeah, I need to make sure I'm clear there. You also mentioned some I haven't used so that's a point. Lurchington fucked around with this message at 21:28 on Aug 2, 2010 |
# ? Aug 2, 2010 18:08 |
|
I haven't myself done a python dev interview but I think it wouldn't hurt to be able to say you know the basics of a few popular python libraries/frameworks like maybe twisted or eventlet, numpy, tkinter or maybe pyqt or pygtk (some kind of gui experience basically), although you have Django covered.
|
# ? Aug 2, 2010 20:01 |
|
Lurchington posted:Alright, I have an in-person technical interview for a python development job, and it's my first one ever really (I've been doing project management for the last 6 years). It might be helpful to brush up on itertools/functools, they're pretty handy and will make your whiteboard examples more impressive.
|
# ? Aug 2, 2010 23:03 |
|
|
# ? Jun 11, 2024 02:36 |
|
Does anybody know of a RSS feed or something one can subscribe to thats comprehensive on all the goings on of the python community? Apparently there was a loving pycon 20 minutes from where I live a few days ago but I missed it because I had no idea it was going on.
|
# ? Aug 3, 2010 00:13 |