|
A A 2 3 5 8 K posted:Some sorts of invalid pages. When you have a database of 400,000 links from all different sources you want to parse, you will find much more that can go wrong with HTML than the authors of any of these packages considered.
|
# ? Jun 8, 2009 18:14 |
|
|
# ? May 11, 2024 21:36 |
|
hi again guys, can someone tell me why the following expression is incorrect listr= [[1,2],[1,3]] newlistr = [lis.append(3) for lis in listr] i understand the proper way to build the list im intending on is to use lis + [3] and not lis.append(3) but why cant i use the property of an object with a list expression? thanks! and why do i get [none, none] as a result.
|
# ? Jun 10, 2009 04:54 |
|
See the discussion on immutable and mutable objects. list.append modifies the original object and doesn't return anything (None).
|
# ? Jun 10, 2009 05:18 |
|
CrazyPanda posted:hi again guys,
|
# ? Jun 10, 2009 05:29 |
|
CrazyPanda posted:hi again guys, What?
|
# ? Jun 10, 2009 05:43 |
|
Because MyList.append(x) doesn't return a new list equal to MyList with an x on the end, it returns None and alters MyList by putting an x on the end. >>> listr= [[1,2],[1,3]] >>> newlistr = [lis.append(3) for lis in listr] >>> newlistr [None, None] >>> listr [[1, 2, 3], [1, 3, 3]] If that doesn't make sense, try to think of it this way: When you use lis + [3], you are asking the computer to figure out what lis with 3 on the end would be. "+" is a function, with two inputs and an output. You can then save this output value somewhere, by making a new list in memory. In your example (when you use lis + [3]) you are saving this output as elements of newlistr. When you use lis.append(3), you are telling the computer to change lis by putting a 3 on the end. This returns None, because it is a command to lis to change itself, not a request for a new list. What you are saving to newlistr is the return values of the command, which is None.
|
# ? Jun 10, 2009 05:45 |
|
A A 2 3 5 8 K posted:Some sorts of invalid pages. When you have a database of 400,000 links from all different sources you want to parse, you will find much more that can go wrong with HTML than the authors of any of these packages considered. word. I worked at a company that spidered about 300 sites daily and grabbed details of specials and poo poo , reformetted them, added the markup and published it. The thing ran on a cluster of 5 machines each running a python script with about 400 microthreads (using stackless) and all using beautiful soup , and god drat is there some horrifying HTML out there. Also a 400 thread spider can rape almost any given site to a smouldering mess in a fraction of a second. Don't do this, but god drat the structure of that thing was fun to write. The actual scrapers however made me hate my life.
|
# ? Jun 10, 2009 10:29 |
|
duck monster posted:The actual scrapers however made me hate my life. Oh god yes writing scrapers continually is a nightmare.
|
# ? Jun 10, 2009 10:57 |
|
I actually prefer writing web scrapers to working with Webservice XML APIs. The tag soup HTML madness is usually nicer that APIs that are just some websites data backed with "<xml>" stuck at the front and "</xml>" tacked on the end. But yeah, writing frameworks to write scrapers in is way more fun than the actual scrapers.
|
# ? Jun 11, 2009 12:54 |
|
His royal newbness checking in. Trying to do an exercise from a book with class. Basically the program is it draws a card randomly and tells you what number and suit, but I am having some trouble with it. Here is what I have so far, I know it is wrong, but I am not sure what I am doing wrong: code:
Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> import cards File "/Users/Jimmy/Documents/cards.py", line 22, in <module> main() File "/Users/Jimmy/Documents/cards.py", line 19, in main rank1 = getRank() NameError: global name 'getRank' is not defined thanks for taking a look. Edit: Added code tags for clarity! Thanks for the suggestion. Balam fucked around with this message at 16:44 on Jun 13, 2009 |
# ? Jun 13, 2009 16:19 |
|
You might want to put that code in [code][/ code] tags so that we can see how it is indented. Are those defs part of the class or separate, for example.
|
# ? Jun 13, 2009 16:23 |
|
Balam posted:His royal newbness checking in. Hint: You're not calling the constructor. No Cards objects are being created. getRank() is a method on the Cards class. It can only be called on a Card object. There is no card object.
|
# ? Jun 13, 2009 17:29 |
|
Zombywuf posted:I actually prefer writing web scrapers to working with Webservice XML APIs. The tag soup HTML madness is usually nicer that APIs that are just some websites data backed with "<xml>" stuck at the front and "</xml>" tacked on the end. All I can say is beautiful soup saved my sanity.
|
# ? Jun 13, 2009 17:39 |
|
Balam posted:His royal newbness checking in. like nbv4 said, you need to instantiate the class to use its methods. Fore main(), try this: code:
code:
|
# ? Jun 13, 2009 23:16 |
|
There is more than one problem with that example. Its a poor example of classes anyways. Why didn't anyone point out that getting rank or suit REPLACES a Card instance's rank or suit with the randomly chosen rank or suit. Or the fact the init does not assign anything to self? Or that init does nothing with the given rank and suit, just replaces them. This site seems to have a decent introduction to classes in python. Here would be a better(?) example of a card deck class in python. code:
hlfrk414 fucked around with this message at 00:32 on Jun 14, 2009 |
# ? Jun 14, 2009 00:12 |
|
Thanks for all the help guys. I guess "class" is something that really takes a while to learn so I am going to keep looking over it. One question for hlfrk414, what does this section of the code do? code:
code:
|
# ? Jun 14, 2009 04:05 |
|
That section checks if a custom set of ranks/suites is defined. "Why" would be a better question -- just in case a fifth suite is added later? His code is a bit bizarre, I would do it like this: code:
|
# ? Jun 14, 2009 04:20 |
|
Aside: http://docs.python.org/dev/py3k/whatsnew/3.1.htmlquote:Enabling a configure option named --with-computed-gotos on compilers that support it (notably: gcc, SunPro, icc), the bytecode evaluation loop is compiled with a new dispatch mechanism which gives speedups of up to 20%, depending on the system, the compiler, and the benchmark. Anyone know if this is getting backported ?
|
# ? Jun 14, 2009 04:35 |
|
I considered adding a card class, but since there were no methods to add to it, it seemed unnecessary. Almost java-like to make a class for pure data, and just use it with 'getters'. I took in a possible rank and suit to show how we could use custom decks, but it does complicate it a bit. My code seems a bit odd because I wanted to represent a deck as something separate from individual cards, where cards could be added, removed, and moved as needed. Custom decks and suits can be used trivially, either to allow different suit names, or more complicated stuff. Randomly choosing a card seems wrong to me, since any game using cards removes the cards, not allowing them to be chosen again, unlike your example. Still, it isn't a very good example a classes, the link I provided goes over classes better than me. If I remember right, the speedup option will not be back-ported because it changes how the interpreter works, breaking compatibility with older versions.
|
# ? Jun 14, 2009 05:37 |
|
hlfrk414 posted:I considered adding a card class, but since there were no methods to add to it, it seemed unnecessary. Almost java-like to make a class for pure data, and just use it with 'getters'. I took in a possible rank and suit to show how we could use custom decks, but it does complicate it a bit.
|
# ? Jun 14, 2009 05:54 |
|
tef posted:Aside: http://docs.python.org/dev/py3k/whatsnew/3.1.html No, it hasn't. It is in unladen swallow for what it's worth.
|
# ? Jun 14, 2009 06:38 |
|
I've done something stupid but for the life of me I can't figure out what. code:
deedee megadoodoo fucked around with this message at 17:12 on Jun 14, 2009 |
# ? Jun 14, 2009 17:10 |
|
HatfulOfHollow posted:
I don't think self = {} does what you think it does code:
|
# ? Jun 14, 2009 17:21 |
|
tef posted:I don't think self = {} does what you think it does poo poo. You're right. I was trying to empty the ProcessList dict and hosed myself.
|
# ? Jun 14, 2009 17:39 |
|
This may be a stupid question but the one thing I don't like about teaching myself a language vs. taking a class is that you never have an opportunity to make sample programs, something that I feel really helps me in reinforcing the education. Is there like a collection or list or something of small programming assignments designed to test your knowledge?
|
# ? Jun 16, 2009 05:08 |
|
Pie Colony posted:This may be a stupid question but the one thing I don't like about teaching myself a language vs. taking a class is that you never have an opportunity to make sample programs, something that I feel really helps me in reinforcing the education. Is there like a collection or list or something of small programming assignments designed to test your knowledge? There are dozens of such lists. Project Euler is one. The contents of any tutorial book is another.
|
# ? Jun 16, 2009 05:24 |
|
Pie Colony posted:This may be a stupid question but the one thing I don't like about teaching myself a language vs. taking a class is that you never have an opportunity to make sample programs, something that I feel really helps me in reinforcing the education. Is there like a collection or list or something of small programming assignments designed to test your knowledge? http://projecteuler.net/ http://codekata.com/ http://forums.somethingawful.com/showthread.php?threadid=2415898
|
# ? Jun 16, 2009 05:44 |
|
Pie Colony posted:This may be a stupid question but the one thing I don't like about teaching myself a language vs. taking a class is that you never have an opportunity to make sample programs, something that I feel really helps me in reinforcing the education. Is there like a collection or list or something of small programming assignments designed to test your knowledge? Check out the python forums: http://python-forum.org/pythonforum/index.php My education was just opening up already built programs, trying to understand them, then coding my own additions and seeing if I could get it to work. Its fun, you get to see how other people code, as well as code yourself, and you even get something useful at the end of it.
|
# ? Jun 16, 2009 09:09 |
|
An odd problem: I'm writing a quick-and-dirty cgi script in python and I can't import a whole bunch of modules. In more detail: one or two things in site-packages are being seen. The other 30 or so aren't (as determined by looking at sys.path). I thought maybe it was easyinstall and eggs but an egg is one of things that are being seen. Actually an old version of SQLAlchemy is being picked up while newer versions are being ignored. I'm sure I'm calling the right version of Python. Ideas?
|
# ? Jun 16, 2009 14:00 |
|
Any suggestions for a free decent UML tool, aimed at Python in particular? Code generation would be a plus.
|
# ? Jun 16, 2009 14:26 |
|
Foiltha posted:Any suggestions for a free decent UML tool, aimed at Python in particular? Code generation would be a plus. Boa Constructor will generate UML diagrams from code. Dia2Py (or is it Dia2Django) will generate Django models from DIA UML. Which is to say DIA generates pretty cool UML.
|
# ? Jun 16, 2009 14:47 |
|
outlier posted:An odd problem: I'm writing a quick-and-dirty cgi script in python and I can't import a whole bunch of modules. What OS/version? Offhand guess: permissions issues? could the ones not being imported not be fully readable by the executing user? Otherwise, it's pretty much got to be something where you're not ACTUALLY looking at the right site-packages, though iirc sys.path should be showing you full absolute file paths, which would make that pretty unambiguous.
|
# ? Jun 16, 2009 18:00 |
|
I am trying to write a python program to manage music and I am thinking about creating a "music library" type mini-database inside of the program. Does anybody know of a good python library that handles this kind of thing or a good approach to this?
|
# ? Jun 16, 2009 22:12 |
|
scrabbleship posted:I am trying to write a python program to manage music and I am thinking about creating a "music library" type mini-database inside of the program. Does anybody know of a good python library that handles this kind of thing or a good approach to this? Absolutely
|
# ? Jun 16, 2009 22:17 |
|
bitprophet posted:What OS/version? OSX10.5, Python 2.5.2. I've got a working solution, although the root problem is still unclear. I pointed the cgi script directly at the python interpreter in question (i.e. using the full path) and that means most of the other modules are being picked up. (Note: most. And I was certainly calling the same interpreter. Hmmm,) Haven't found the common link as yet to the non-loading ones, although I have discovered that (logically) modules installed with "setup.py develop" don't load.
|
# ? Jun 17, 2009 11:00 |
|
This is a little program I wrote to emulate n number games of Craps and tells you how many times you win or lose. If I emulate just one game there is no problem but anything more and it seems like it is looping infinitely, I can't seem to resolve this.code:
|
# ? Jun 17, 2009 15:32 |
|
Balam posted:This is a little program I wrote to emulate n number games of Craps and tells you how many times you win or lose. If I emulate just one game there is no problem but anything more and it seems like it is looping infinitely, I can't seem to resolve this. If value2 comes up 7, you'll still continue through the while loop since you have an "or" statement there. Try changing the while statement to: code:
code:
|
# ? Jun 17, 2009 15:59 |
|
ok, I fixed it spankweasel and it works well. I did find another problem too. Wins and Loses never got above one, no matter how many games played because I was defining them both as 0 within in the loop so each time it would go around and reset their values to zero. edit: spellcheck.
|
# ? Jun 17, 2009 16:18 |
|
I still draw up little truth tables as soon as a logical operation looks like its going to have more than 3 or 4 terms
|
# ? Jun 17, 2009 17:17 |
|
|
# ? May 11, 2024 21:36 |
|
Does anyone have some experience with numpy? I'm trying to copy a 2-dimensional array into a third dimension. I was wondering if there was a more efficient way to do what I am currently doing:code:
|
# ? Jun 17, 2009 22:10 |