|
Thermopyle posted:The universal answer to this is to write something to solve a problem you have. Hahaha I suppose I'll continue just plodding through the books for now. Its funny because this seriously looks nigh impossible to me
|
# ? Oct 13, 2010 02:01 |
|
|
# ? Jun 12, 2024 23:13 |
|
tripwire posted:loving SOLD Used it this afternoon, and was impressed with the source control integration and how it handle virtualenvs. Both of those were a bit wack on PyDev. My boss and some other people had been loosely following the development, so I think my company might spring for some licenses
|
# ? Oct 13, 2010 02:52 |
|
tbp posted:Hahaha I suppose I'll continue just plodding through the books for now. Its funny because this seriously looks nigh impossible to me Yeah, I can't even fathom where to begin with anything like that. It's so abstract to me right now.
|
# ? Oct 13, 2010 14:20 |
|
standardtoaster posted:Yeah, I can't even fathom where to begin with anything like that. It's so abstract to me right now. The first project given is pretty easy. The key is to stop thinking about the code initially, and just start writing down a common sense procedure. 1) Write something to organize your download directory. Think of some steps. - Set the path to your download directory. (You'll want to use os.path, but to keep it simple you can hardcode it. i.e, "C:\MyDownloads\") - Create a folder for every letter in the alphabet. i.e, for letter in range('a','z') You can use methods provided in the os module to do so. - Loop through all of the files in the download folder and store their path/filename.extension as a string in a list. - Sort the list - Loop through the list and use provided methods in the os module to move each file into the correct folder, one at a time. It's not so abstract anymore, you can probably write a script to do this now. When you have this working consider trying to do the same thing but instead of sorting the files into folders alphabetically, sort them into folders by media type. Some psuedocode: code:
First Time Caller fucked around with this message at 18:20 on Oct 13, 2010 |
# ? Oct 13, 2010 18:05 |
|
What is the best way to modify a list in arbitrary, flexible ways? For example, to replace every element for which function f() returns true with three new elements returned by a function g(). E.g.code:
I'm sure I could find some method to do this based on insert() and pop() and such, but I bet there's some elegant way to do it. I thought of using a list comprehension, but I don't see how to expand one element to more than one. EDIT: I found a big part of the answer: slice assignments. "a[1:1] = [2,3,4]" will insert 2,3,4 at offset 1, replacing the original element 1. Stabby McDamage fucked around with this message at 18:53 on Oct 13, 2010 |
# ? Oct 13, 2010 18:40 |
|
Stabby McDamage posted:What is the best way to modify a list in arbitrary, flexible ways? For example, to replace every element for which function f() returns true with three new elements returned by a function g(). E.g. sounds like a variation on reduce with map
|
# ? Oct 13, 2010 18:51 |
|
I don't see how reduce could be related, since no part of this involves condensing a list down to one value. For map, I thought of that, but I don't see how that could be used here, because if the given function returns (2,3,4), then the tuple (2,3,4) gets included in the list, not the elements 2,3,4. EDIT: This is my best effort at implementing the fancy_construct used above. I think it's pretty ugly and non-pythonic...surely there's a better way. code:
Stabby McDamage fucked around with this message at 19:09 on Oct 13, 2010 |
# ? Oct 13, 2010 18:55 |
|
Stabby McDamage posted:I don't see how reduce could be related, since no part of this involves condensing a list down to one value. Sure it does. You are condensing a list down to one value, which happens to be a new list. code:
|
# ? Oct 13, 2010 19:19 |
|
standardtoaster posted:Yeah, I can't even fathom where to begin with anything like that. It's so abstract to me right now. Lets stick to it and learn this poo poo then. I'll continue with that PDF and soon we'll be taking on those tasks like its not problem
|
# ? Oct 13, 2010 19:21 |
|
You can reduce it with list.__add__, I think, if you return [2,3,4] rather than (2,3,4); it's a reduction to a single value (which is itself a list)code:
Edit: beaten like an AST-walking interpreter by ShoulderDaemon
|
# ? Oct 13, 2010 19:23 |
|
ShoulderDaemon posted:Sure it does. You are condensing a list down to one value, which happens to be a new list. Ah, I would never have thought of that. Thanks.
|
# ? Oct 13, 2010 19:40 |
|
tbp posted:Lets stick to it and learn this poo poo then. I'll continue with that PDF and soon we'll be taking on those tasks like its not problem Please do, it's worth it! Feel free to ask questions. Did the post by First Time Caller help give you an idea what you should be thinking about?
|
# ? Oct 13, 2010 20:00 |
|
Thermopyle posted:Please do, it's worth it! ...sort of. I get the idea that I shouldn't be going into solving problems with 'what code should I write' instead of 'what steps should the code take'. But even the first step is lost on me. Set a path? Huh?
|
# ? Oct 13, 2010 20:54 |
|
tbp posted:...sort of. I get the idea that I shouldn't be going into solving problems with 'what code should I write' instead of 'what steps should the code take'. But even the first step is lost on me. Set a path? Huh? The general idea of a filepath in the context of an operating system is a fully qualified reference to the location of the file, including its name. e.g, where it is on your hard drive. I'm sure you've seen this before when traversing your filesystem looking for a particular file. "C:\Windows\SecretPornSpot\BucksBuckingBitches.wmv" You'll need to be able to reference the location of your downloads directory several times in your program. The easiest way to do this instead of typing it out several times is to declare a variable that holds the value. code:
It's likely that this will all make more and more sense as you go along. If you want to learn in a more traditional environment, MIT has an online Python course and actually, so does Google. A lot of the things they do in the MIT course are kind of ...odd... for Python but it will still teach you how to program so you might want to do the Google course instead, if you so choose. I personally think that neither of these are as good as Think Like A... so I would suggest using them as supplementary tools only. First Time Caller fucked around with this message at 23:25 on Oct 13, 2010 |
# ? Oct 13, 2010 23:15 |
|
ShoulderDaemon posted:Sure it does. You are condensing a list down to one value, which happens to be a new list. what he said edit: Bah I'll use this to say that I'm 2 days into PyCharm and I'm really liking it. Loving the code completion that actually works for a lot of duck typing and the highlighting for changes in a revision controlled file. Lurchington fucked around with this message at 00:15 on Oct 14, 2010 |
# ? Oct 14, 2010 00:11 |
|
Lurchington posted:what he said The one thing I'm missing is code-fragment mode while debugging; you can do that with manually with pdb but for some reason its missing in the gui.
|
# ? Oct 14, 2010 00:34 |
|
First Time Caller posted:The general idea of a filepath in the context of an operating system is a fully qualified reference to the location of the file, including its name. e.g, where it is on your hard drive. I'm sure you've seen this before when traversing your filesystem looking for a particular file. "C:\Windows\SecretPornSpot\BucksBuckingBitches.wmv" So by using that string the shell will know the go to the documents folder? Yeah that does make a bit more sense now.
|
# ? Oct 14, 2010 01:22 |
|
tbp posted:So by using that string the shell will know the go to the documents folder? Yeah that does make a bit more sense now. Not necessarily but I think you're getting it. That statement alone doesn't do anything special except bind the value of the string to a variable name. The Python interpreter doesn't know what it does or what it's for, but you do. This is where the Python docs would come in handy. The os module provides many methods for interacting with your computers filesystem. http://docs.python.org/library/os.html#os.mkdir You'll notice the method header looks like this: os.mkdir(path[, mode]). It's read as "the module os provides a method mkdir that takes one required parameter, path, and one optional parameter, mode". You can call this method like: code:
First Time Caller fucked around with this message at 02:24 on Oct 14, 2010 |
# ? Oct 14, 2010 02:21 |
|
Thank you a lot First Time Caller I hope you expect to be answering many questions in the coming pages I think the first project I may outline for myself is to do something along the lines of that - but sort information from the game Football Manager 2010. Its a really stat-heavy simulation game, basically a glorified spreadsheet, so writing a program would be both useful practice and useful in-game.
|
# ? Oct 14, 2010 16:32 |
|
tbp posted:Thank you a lot First Time Caller I hope you expect to be answering many questions in the coming pages I'm learning the language as well and it helps me a lot by helping others so I'd be more than happy to answer as many questions as I can. Some more experienced python programmers will probably need to jump in at times and correct me but that's all part of the learning process. That's a great idea for a first project. Can you post up one of the files that you'd be parsing for FM2010?
|
# ? Oct 14, 2010 20:13 |
|
I have an annoying problem. I feel I can't be the first to come across it, but neither google nor docs have been of any help to me so far. I have a largish 2d numpy char array (exact size varies, but typically ~17000x700 elements) and from this I want to compute a bool array of the same size which is True everywhere except in positions that contain one of a few chars (almost always 2-3 and always nonconsecutive), where I want it to be False. I also need this to be Fast! This snippet solves my problem but is too slow for my liking: code:
This one is even worse: code:
Making a C extension for this would probably be stupidly easy, and would probably also be the fastest solution in the end, but my gut feeling tells me there's probably something in the numpy library that I missed. I can't be the first one who wants to do this stuff.
|
# ? Oct 14, 2010 21:48 |
|
Maybe its not a big deal with three characters in your list of excluded letters, but you should probably turn that string into a set if you want faster membership testing. How you'd do that in numpy without calling a python function on each cell is beyond me though.
|
# ? Oct 16, 2010 19:00 |
|
code:
|
# ? Oct 16, 2010 19:18 |
|
Turns out I wasn't first at all. I was so not first it's already in punctuation.code:
|
# ? Oct 16, 2010 22:38 |
|
code:
e: oh hurf that 'depth' in the max call needs to be depth-1, it still seems slow though. Opinion Haver fucked around with this message at 01:34 on Oct 17, 2010 |
# ? Oct 17, 2010 01:18 |
|
First Time Caller posted:I'm learning the language as well and it helps me a lot by helping others so I'd be more than happy to answer as many questions as I can. Some more experienced python programmers will probably need to jump in at times and correct me but that's all part of the learning process. Yeah I'll do this in a bit. Basically I'm looking to sort by stats to have a go-to reference for what players to purchase etc.
|
# ? Oct 17, 2010 01:26 |
|
Do you guys have any strategies for refactoring and maintaining large systems in Python? I began working on Python over a year ago after working as a Java programmer for a number of years. I loved Python from the start. However now that the programs that I have been working on (mostly big Django apps) have grown in size and complexity, I am starting to miss some of the rigidity that came with Java. Static typing, forcing the catching or passing of exceptions, a compile step were all helpful. Forcing everything into the object paradigm, while obnoxious, was also useful sometimes. Does anyone have any advice on disciplines that I should be adhering to when writing Python code to improve future maintainability? Does anyone have any advice or suggestions for tools for refactoring or checking my code?
|
# ? Oct 17, 2010 04:32 |
|
Tests!
|
# ? Oct 17, 2010 06:10 |
|
sink posted:Do you guys have any strategies for refactoring and maintaining large systems in Python? You might want to take a look at pylint?
|
# ? Oct 17, 2010 12:20 |
|
Just found this subforum and thread. Pycharm is awesome, thanks.
|
# ? Oct 19, 2010 00:16 |
|
libberlibber posted:Just found this subforum and thread. Pycharm is awesome, thanks. PyCharm cool thing of the day: VCS (we use mercurial) history of the active file your editing. 'who messed up my poo poo?' *check the history* 'hmm, sammy jones in changeset 63, that bastard'
|
# ? Oct 19, 2010 15:27 |
|
Lurchington posted:PyCharm cool thing of the day: VCS (we use mercurial) history of the active file your editing. Yeah their VCS stuff is pretty drat nifty. The only major issue i have left with pycharm is: - Debugger seems to have problems with hitting breakpoints of modules i don't import directly: code:
- It can sometimes bug the living poo poo out of me with its inspections, most of the time its fantastic. "Yes PyCharm i know that line isn't right because i only started typing the first loving letter of it" But poo poo this is easily the best IDE i have used for python. Also i have a question for you guys i am trying to wrap our existing hellish ftplib wrapper library () into something more Pythonic. Pythonic is the new buzzword at work, since we are porting/rewriting our existing pre 2.0 era python libraries into the much more modern 2.5.4 era (blame arcgis) everything should be Pythonic (<insert something>-like objects, list comphrensions, packages, etc). Its a good idea but its getting to the point where its difficult to make certain things "Pythonic". Anyways the library does stuff like resuming transfers, partial downloading, and properly expanding, parsing some internal binary formats and lots of other stuff. All in all the library is ~8k lines of code (excluding comments) crammed into half a dozen functions in a single .py file: I have already done everything else, i have the core of it, its just when it comes to resumable downloads(this gets used alot, ~2GB files we want to resume, and it happens alot). To resume a download, we append a .lok extension to the filename, and only when the transfer is completed do we rename the file to the correct extension. This way if the transfer fails, when we reconnect we see .lok file and just continue the transfer from where it left off. However i have no idea how to work something like this into a file like object : code:
code:
Pythonic
|
# ? Oct 19, 2010 18:28 |
|
UberJumper posted:This however is considered unpythonic by our code review and was rejected Does anyone have any ideas of how the gently caress i am supposed to make this pythonic? Uploading a file is fine because i can wrap all of the resuming stuff. I feel pretty stupid atm =( Well. That's more than slightly insane. They can just reject something as "un-pythonic" without providing any alternatives or suggestions? That's now how code review works. I actually prefer your original code. Is it considered un-pythonic in any specific way, or are you just expected to be a mind reader?
|
# ? Oct 19, 2010 18:36 |
|
I have a weird rear end question to ask for those familiar with using IDLE on Linux. I had just starting programming in python but I currently only have access to an Ubuntu machine. I ran a simple program but when it didn't run correctly, I closed the window made the corrections and ran the module again only to see an error saying that the "Python shell is already executing a command". The only way to fix the problem was to close IDLE completely and reopen it. I never encountered this problem using IDLE in windows so I have no idea what might be causing it. Not only am I knew to the language but I am also new to the OS. Any help for a complete newbie?
|
# ? Oct 19, 2010 20:09 |
|
Doesn't answer your question directly but I have an alternative solution. Don't use IDLE. You'll be able to practice your terminal-fu at the same time!
|
# ? Oct 19, 2010 21:12 |
|
I didn't think this was worth it's own thread - I'm a beginner programmer, aspiring to be a game developer. Currently doing a university certificate to improve my rusty maths skills, which comes attached with a paper in C#. I know the basics and applications of loops, if/else, classes, arrays and a few other things in C#, and it seems like python would be a really good language to tinker about with right now - especially with making small simple games and applications, and how it can be used in web development later on which also interests me greatly. Its syntax is simple and easy to understand, and I figure it would be a friendly language to learn more programming concepts in order to become more efficient and learn. Two questions spring to mind. I am used to working in visual studio, are there any IDEs for python that aren't too resource intensive for my (soon to be upgraded) 4 year old laptop? Or is it recommended to use notepad++ and a separate compiler so I learn without being auto-corrected? Question 2, I have installed python 2.7 in order to use pyglet, but the pyglet installation doesn't seem to want to work and says it requires python 2.4 or higher. I heard it was very easy to make forms and do game-related things. Is this a common problem? Running 32-bit Vista (sigh). Thanks in advance.
|
# ? Oct 19, 2010 21:40 |
|
I'm writing a script to sit between a program's web API (it's XBMC to be specific) and clients that access that API. For example, you can hit XBMC with... code:
My question is this...what's a lightweight framework/web server that would be good for implementing this? The only thing I'm somewhat familiar with is Django, which just seems too massive for such a thing, besides the fact that the docs constantly say not to use the built-in webserver for anything in production. I can't imagine any realistic scenario where there would be more than a few clients and a few XBMC installations, so I definitely don't need anything that is meant to handle massive amounts of requests. niff posted:I am used to working in visual studio, are there any IDEs for python that aren't too resource intensive for my (soon to be upgraded) 4 year old laptop? Or is it recommended to use notepad++ and a separate compiler so I learn without being auto-corrected? Give PyCharm a try, people seem to be diggin' it.
|
# ? Oct 19, 2010 22:32 |
|
niff posted:Two questions spring to mind. I am used to working in visual studio, are there any IDEs for python that aren't too resource intensive for my (soon to be upgraded) 4 year old laptop? PyCharm as previously suggested or Eclipse+PyDev. I prefer Eclipse, but that's just me. As for pyglet: pyglet installer posted:pyglet requires Windows XP (Windows Vista is not supported at this time). Thermopyle posted:My question is this...what's a lightweight framework/web server that would be good for implementing this? This sounds like a good project for Web.Py
|
# ? Oct 20, 2010 05:01 |
|
First Time Caller posted:This sounds like a good project for Web.Py And for the love of God, don't confuse it with the newer project that thought it would be a great idea to name itself "web2py". Totally different (and crap). Also check out Bottle, which is in the same vein as web.py, to see which one has a more pleasing-to-you API.
|
# ? Oct 20, 2010 05:09 |
|
|
# ? Jun 12, 2024 23:13 |
|
I had not seen Bottle before but looking through the source code it looks great. I might actually have to learn the poo poo out of it as part of my python learning experience. 2100 lines of code is terribly digestible, even by someone as new as me.
|
# ? Oct 20, 2010 06:17 |