|
Centipeed posted:I tried Project Euler when I was first getting into a programming language, but the problem is that most of the thinking you have to do (Or I had to do, at least) was mathematical rather than "How do I do this with the language I've got in front of me?". Did anyone else find this? I can see where you're coming from, but a lot of languages have different constructs that can help you solve the problem easier than if you had used another language. The hard part is figuring out how to apply those constructs to the problem at hand. Also remember that even if you found a solution to the problem, that depending on the paradigm your language uses, you might not be able to implement it the way you had solved it.
|
# ? Apr 24, 2009 19:18 |
|
|
# ? May 14, 2024 08:36 |
|
MEAT TREAT posted:I can see where you're coming from, but a lot of languages have different constructs that can help you solve the problem easier than if you had used another language. The hard part is figuring out how to apply those constructs to the problem at hand. Can you give an example? I've done twenty Project Euler problems but haven't noticed any use for any traditional language features like object orientation, higher-order functions, code as data. The Python, Java and Haskell solutions are more or less the same as the C. The nicer solutions use a language with support for abstract algebra such as Mathematica or PARI/GP.
|
# ? Apr 24, 2009 19:39 |
|
The Haskell solutions use higher-order functions all the time and they're very much different from the C or Java solutions. Project Euler is good for getting used to the syntax and some basic idioms of a language. I used Project Euler when learning Haskell and I think it's especially good for learning it because it makes you use infinite lists, higher-order functions, laziness and forces you to think in a functional instead of an imperative manner. Anyway, I think it's good for getting warmed up with a language. But once you've solved 80 or so problems, it's not about whether you can implement the solution in your programming language of choice, it's about whether you know a mathematical trick or method behind some problem, so that's why I stopped solving them around then.
|
# ? Apr 24, 2009 20:14 |
|
Someone needs to put together a Project Euler type website which doesn't have a focus on maths. I don't know what the possibilities would be, though. Just some simple programming problems that don't aim to take advantage of ANY particular language's abilities. Hello World 2.0 type challenges.
|
# ? Apr 24, 2009 22:51 |
|
Centipeed posted:Someone needs to put together a Project Euler type website which doesn't have a focus on maths. I don't know what the possibilities would be, though. Just some simple programming problems that don't aim to take advantage of ANY particular language's abilities. Hello World 2.0 type challenges. But... that's what makes the problems work. Sure, you could make up elaborate word problems that the solution is "implement this algorithm", but that's exactly what the math problems allow you to do without all of the extra fluff. It's not like you need a particularly rich math background. Just look up the solutions to the problems on wiki or in a math text, and then implement the solution in your language of choice. Ultimately, if you can't do the math described in the problems, then you're missing a prerequisite to good software engineering. Here's an opportunity to get better at both!
|
# ? Apr 24, 2009 23:14 |
|
tbradshaw posted:But... that's what makes the problems work. Sure, you could make up elaborate word problems that the solution is "implement this algorithm", but that's exactly what the math problems allow you to do without all of the extra fluff. Not every programming problem involves implementing algorithms. It could be something like "design a system that does this:"
|
# ? Apr 25, 2009 02:38 |
|
Here you go: UVa Online Judge It only supports Java, C, C++, and PASCAL (yeah I know it's a python thread, but if you just want problems to solve, you can do them without submitting) but there are TONS of great problems here. We had to do several for a Data Structures and Algorithms class, and they're pretty fun. Not only do you get to solve problems, it analyzes how fast your program is and ranks your against other people that have solved the problems. My instructor (Glen Downing) is #1 for a bunch of problems (or was last year anyways). ndrz fucked around with this message at 04:05 on Apr 25, 2009 |
# ? Apr 25, 2009 04:02 |
|
BeefofAges posted:Not every programming problem involves implementing algorithms. It could be something like "design a system that does this:" You might want to revisit what "algorithm" means.
|
# ? Apr 25, 2009 04:22 |
|
tbradshaw posted:You might want to revisit what "algorithm" means. shhh, you know what I meant!
|
# ? Apr 25, 2009 08:19 |
|
e: I am dumb, nevermind.
Luigi Thirty fucked around with this message at 16:27 on Apr 25, 2009 |
# ? Apr 25, 2009 16:17 |
|
Okay, here is my first stupid newbie python question. Let there be no mistake about it, I am very green with python. Here's the deal: I am trying to run through this project that shows how python can be used with curses to make some spiffy apps. It looks straightforward enough, and so I make a go at it. In the middle of the page, there is this bit of code: code:
code:
I'm thinking that it is something not too difficult to take care of, but I don't understand what is causing it. I can say with total certainty that curses is installed on OS X. he;lp
|
# ? Apr 28, 2009 01:47 |
|
LE posted:Okay, here is my first stupid newbie python question. Let there be no mistake about it, I am very green with python. Works on my machine, stock python 2.5.1 from Apple (OS/X) what version (python --version) are you running?
|
# ? Apr 28, 2009 01:51 |
|
LE posted:Okay, here is my first stupid newbie python question. Let there be no mistake about it, I am very green with python. >>>import curses >>>dir(curses) It should print a list of every class or function contained in curses. You can apply dir() to any of the elements of this list if they contain new classes or functions as well.
|
# ? Apr 28, 2009 01:53 |
|
LE posted:Okay, here is my first stupid newbie python question. Let there be no mistake about it, I am very green with python. Ho ho, I'm going to catch this one first yet again. Don't name your file curses.py When you do import curses it looks in the current directory first for a file named curses.py and in your case it's finding itself (yes, it can do this) and loading that as the curses module. If you rename your file it won't find something named curses.py in the current directory and it will go ahead and look on the PYTHONPATH for a curses.py to import and it should find the appropriate one. edit: put in the quote and sirens to hope LE didn't miss this right below me... No Safe Word fucked around with this message at 02:03 on Apr 28, 2009 |
# ? Apr 28, 2009 01:55 |
|
m0nk3yz posted:Works on my machine, stock python 2.5.1 from Apple (OS/X) what version (python --version) are you running? code:
|
# ? Apr 28, 2009 01:55 |
|
No Safe Word posted:Ho ho, I'm going to catch this one first yet again. Yep, you got it. Thank you!
|
# ? Apr 28, 2009 02:21 |
|
No Safe Word posted:Ho ho, I'm going to catch this one first yet again. D'oh. So painfully obvious.
|
# ? Apr 28, 2009 13:49 |
|
outlier posted:The situation is that I have some 3rd party code calling a commandline program, waiting for the results, then munging them in various ways before returning them to a webservice. And when the user gets bored and terminates the request, the called commandline process seems to hang around. Curious. Following myself up again: after perusing the code for subprocess, it seems that if a subprocess is not completed by the time the owning object is disposed of, it gets stashed into a list in subprocess called "_active", where it sits until checked by the next call to subprocess. Weird. Anyone have any insight on this?
|
# ? Apr 28, 2009 15:20 |
|
m0nk3yz posted:D'oh. So painfully obvious. Yeah, but obviously not uncommon since the same thing happened a little over a week ago It used to bite me pretty badly when I'd name my C files test.c and just run make test and try and run it. test is a shell builtin that will get precedence and make test compiles test.c into a binary named test
|
# ? Apr 28, 2009 15:33 |
|
Is there any reasonable way to release a library for both Python 2 and 3? From what I can tell from the documentation and mailing list, while some code might work unmodified on 2.6 and 3.0, getting 2.4 and 2.5 code to work is unlikely even with 2to3. PyPI doesn't seem to use the version for source uploads, so I can't upload a 2.x and 3.x tarball. I'm playing with the idea of only releasing for 3.x from now on, but there's probably still many people stuck with version 2. I know there are a few people here that maintain large Python libraries, what do you suggest?
|
# ? Apr 29, 2009 21:45 |
|
I want to use a C++ library (libraw) in my program. Is there any way to import a .h file for use with ctypes or do I have to recreate every struct by hand? I have a very very small amount of cython experience and this page looks so promising: http://docs.cython.org/docs/external_C_code.html#external-declarations Am I on the right track?
|
# ? Apr 29, 2009 22:48 |
|
sund posted:Is there any way to import a .h file for use with ctypes or do I have to recreate every struct by hand? http://docs.cython.org/docs/external_C_code.html?highlight=extern#referencing-c-header-files ?
|
# ? Apr 30, 2009 01:39 |
|
Janin posted:Is there any reasonable way to release a library for both Python 2 and 3? From what I can tell from the documentation and mailing list, while some code might work unmodified on 2.6 and 3.0, getting 2.4 and 2.5 code to work is unlikely even with 2to3. PyPI doesn't seem to use the version for source uploads, so I can't upload a 2.x and 3.x tarball. I'm playing with the idea of only releasing for 3.x from now on, but there's probably still many people stuck with version 2. This really depends on your goal - if you goal is 2.4/2.5 compatibility, you're not going to be able to support 3.x without significant changes. If you can stick to 2.6 support only, 3.0 support in the same code base is pretty simple (minus the bytes/string stuff). You can upload to PyPI and mark it with the trove classifiers Programming Language :: Python :: 3/Programming Language :: Python :: 2.6 and people should be able to find it. I've seen people actually upload two packages - python2-pkg and python3-pkg, but that's inefficient. If I were you, I would probably only support 2.6 and 3.x in the same package. YMMV - I would not however, just upload a 3k version.
|
# ? Apr 30, 2009 14:07 |
|
m0nk3yz posted:This really depends on your goal - if you goal is 2.4/2.5 compatibility, you're not going to be able to support 3.x without significant changes. If you can stick to 2.6 support only, 3.0 support in the same code base is pretty simple (minus the bytes/string stuff). You can upload to PyPI and mark it with the trove classifiers Programming Language :: Python :: 3/Programming Language :: Python :: 2.6 and people should be able to find it. It has to support 2.4 and 2.5. Supporting 2.6 is very easy, since it's mostly backwards-compatible. I want to have a version for 3.0, since apparently the 3.0 standard library's implementation of this format has some issues, but that's not possible if it involves sacrificing support for 2.4. Splitting it into two separate packages sounds like a good idea -- do you think it'd be better to have 2.x `libname` and `python3-libname`, or vice-versa?
|
# ? Apr 30, 2009 18:31 |
|
Janin posted:Splitting it into two separate packages sounds like a good idea -- do you think it'd be better to have 2.x `libname` and `python3-libname`, or vice-versa? this sounds fine for now, but remember to install as libname, even if the name on pypi is python3-libname I swear there was discussion about enhancing pypi to support this stuff, but I can't recall
|
# ? Apr 30, 2009 22:15 |
|
m0nk3yz posted:this sounds fine for now, but remember to install as libname, even if the name on pypi is python3-libname PyPi needs about a dozen such enhancements, such as this, or recognizing that a package is a beta and thus installing the previous stable release by default(figuring that one out during the Django 1.1 alpha release was fun...)
|
# ? Apr 30, 2009 23:17 |
|
Can someone explain decorators to me as if I were a child? I went through the first couple pages of the Pyglet tutorial, and they make use of them, but I've looked around at explanations and all of them cause me to start zoning out half way through. So, if it's at all possible, an explanation of Decorators that a five year old would understand.
|
# ? May 1, 2009 13:50 |
|
Centipeed posted:Can someone explain decorators to me as if I were a child? I went through the first couple pages of the Pyglet tutorial, and they make use of them, but I've looked around at explanations and all of them cause me to start zoning out half way through. A function is a list of instructions. A decorator changes that list - sometimes it adds extra instructions that happen first, or instructions to do last. Sometimes a decorator takes that first list of instructions and takes notes about them. Other times decorators don't do any of that - sometimes they change what happens when it's finished doing the list. Or in less subtle terms: a decorator is a function that takes a function as its first argument, and returns a function. This allows you to change the original function. You can do whatever you want inside the decorator. Creating wrappers is common. Another usage is for marking the function in a registry. You could also change the return value using a wrapper. For example, the Django web framework has the decorator @login_required. If you use this with a view function (which displays pages), if Django sees that the user isn't logged in, it doesn't execute the original function at all. Instead, it sends them to a login page, and then back to the original page. The decorator does this by wrapping the original function. A more complex example: You can use decorators to memoize a function. What this means is that it caches return values from the function. If you call the function with the same arguments ten times, it'll execute the function only the first time, and give you back the cached value for the following nine times. This also makes use of a wrapper.
|
# ? May 1, 2009 14:46 |
|
Centipeed posted:Can someone explain decorators to me as if I were a child? I went through the first couple pages of the Pyglet tutorial, and they make use of them, but I've looked around at explanations and all of them cause me to start zoning out half way through. code:
Milde posted:Or in less subtle terms: a decorator is a function that takes a function as its first argument, and returns a function. This allows you to change the original function. You can do whatever you want inside the decorator. Creating wrappers is common. Another usage is for marking the function in a registry. You could also change the return value using a wrapper.
|
# ? May 1, 2009 17:23 |
|
Janin posted:Decorators don't have to return functions, they can return anything. Yes, you might use it to return some other kind of callable object. You could return any other type of object too, I suppose, though I'm not sure I've ever seen that done.
|
# ? May 1, 2009 17:31 |
|
The only time I've seen a decorator return a non-callable is to return a property type in a class body.
|
# ? May 1, 2009 22:39 |
|
In interactive mode, when I reload a module that imports other modules, how do I reload those imported modules? Should I just reload all of them?
|
# ? May 2, 2009 02:22 |
|
Ok I'm having an interesting problem trying to get some code to run on Google App Engine (Python). It works fine in the SDK locally, just not when I upload it. I downloaded itunes-connect-scraper and got it to work locally in the google app engine SDK. http://code.google.com/p/itunes-connect-scraper/ Then I hacked it up some and made it write to the GAE data store. I've uploaded it to my real GAE application but unfortunately it doesn't work there. I've put in a bunch of logging and debugging and I know that it downloads the tar.gz files (or at least gets the http headers like it is), the error is when it tries to un-gzip the file. code:
code:
code:
code:
I'm wondering if anyone knows if GAE has some problems with txt.gz files or something stupid like that. I can't think of any other reason why it would work locally but not on the GAE server. Got any ideas for more debugging I could do? One weird thing is the HTTP headers on GAE dont tell me the content length. How can I print out the size of the tar.gz file I just downloaded? tayl0r fucked around with this message at 04:32 on May 2, 2009 |
# ? May 2, 2009 04:28 |
|
Use the urlfetch api for google app engine: http://code.google.com/appengine/docs/python/urlfetch/overview.html urllib2 is awful.
|
# ? May 2, 2009 04:32 |
|
I wanted to write a quick game in Python and use classes so I could learn and write something fun. It's like the word game Boggle, except that I can tell the letter grid class to use any number for the n by n matrix of letters, so for example if I give it 4, it'll return something like:code:
Everything is written except for the word validating stuff. I don't mean checking words against a dictionary to see if they're valid English words, I mean checking if user input is valid in the grid. I tried writing out a function that would generate all 2-letter words hoping that it would help me visualize what it should look like, but I tried writing it recursively and Python didn't like it. Here's what I wrote to generate all valid 2-letter combinations in a grid: code:
|
# ? May 2, 2009 05:27 |
|
checkeredshawn posted:A friend suggested that instead of figuring out all possible combinations, try to check to see if the first letter is in the matrix, then for each of those matches continue to see if the second letter is in their neighbors, etc. but I couldn't visualize how to write that out. If anyone wants to help and has any questions about the above code or the rest of the code I'd really appreciate any suggestions and I can explain how I implemented stuff. I realize it might have been easier to not use classes but I wrote it this way to learn how to use classes in Python, not necessarily to write it the most efficient and minimal way possible. Your friend's suggestion is good. The number of possible combinations is huge, even if you're limiting words to 4 letters. I'd use a general strategy of first finding all the coordinates on the board that have the first letter, and then finding all the points adjacent to that that have the next letter, and so on, until you find a path that gets to the end of the word. You'll want to make a utility function like "findAdjacentCoordinatesWithLetter" that takes in a coordinate and a letter.
|
# ? May 2, 2009 05:58 |
|
tef posted:Use the urlfetch api for google app engine: Do you think what I'm trying to do would even work since GAE wont let you modify the referer? GAE posted:Request Headers
|
# ? May 2, 2009 06:27 |
|
Well if it is disabled in the api, I imagine what you're trying to do won't work on google app engine at all. The local api will just be wrappers around the standard library, but the implementations at google have been modified for the sandbox. Edit: What you are doing is trying to circumvent the security policy by using an unsupported api. Which is why it is not working, and will never work.
|
# ? May 2, 2009 06:29 |
|
HOLY poo poo! Just when I was about to give up, it works! I switched it over to use urlfetch (was pretty easy) and it still wasn't working. Got the same error- bad gzip data. I printed out what it was downloading and there was my data, already un-gzipped! I wonder why GAE automatically ungzips .txt.gz files if you download them? that seems broken.
|
# ? May 2, 2009 06:46 |
|
|
# ? May 14, 2024 08:36 |
|
The Evan posted:In interactive mode, when I reload a module that imports other modules, how do I reload those imported modules? Should I just reload all of them? ipython has dreload (deep reload) but with normal python, I think you have to reload all.
|
# ? May 2, 2009 07:30 |