|
You can encode a set of Booleans as a number using something like this, though there might often be a better way of doing whatever you are trying to do:code:
|
# ? Apr 29, 2013 21:34 |
|
|
# ? May 9, 2024 05:16 |
|
I am completely new to programming and am playing around with Python after learning some basics on CodeAcademy. I tried using Notepad++ on a friend's recommendation but it turns out getting Python code to run from it is a pain. The OP of this thread is mostly going over my head and the tutorial on setting up VIM is much more advanced and complicated than anything I need at this point. What is a good, simple IDE to write and run Python code? The wiki has a huge list and I don't know which to pick.
|
# ? May 1, 2013 05:35 |
|
dantheman650 posted:I am completely new to programming and am playing around with Python after learning some basics on CodeAcademy. I tried using Notepad++ on a friend's recommendation but it turns out getting Python code to run from it is a pain. The OP of this thread is mostly going over my head and the tutorial on setting up VIM is much more advanced and complicated than anything I need at this point. What is a good, simple IDE to write and run Python code? The wiki has a huge list and I don't know which to pick. Why not just write your code in Notepad++ and then run it from an ordinary command line?
|
# ? May 1, 2013 05:54 |
|
^^^ Because he's probably in Windows and the Windows command line is ghetto as helldantheman650 posted:I am completely new to programming and am playing around with Python after learning some basics on CodeAcademy. I tried using Notepad++ on a friend's recommendation but it turns out getting Python code to run from it is a pain. The OP of this thread is mostly going over my head and the tutorial on setting up VIM is much more advanced and complicated than anything I need at this point. What is a good, simple IDE to write and run Python code? The wiki has a huge list and I don't know which to pick. I really, really like Spyder 2. It comes with Pythonxy, which is basically a big executable full of additional python libraries (numpy and others) and IDEs. Pythonxy is aimed toward people who want to make a switch from MATLAB to Python on Windows systems. It's also free. Even if you're not interested in any of the computational stuff, it's still a great starting point simply because it gives you the option of installing a bunch of different IDEs (so that you can try out a bunch of them out and then keep whichever one you like best) and a bunch of extra libraries to play with (although they're all optional components that you can add later). Spyder 2 is as simple as you want, but it's also incredibly easy to run your code in it. It comes with a command-line interpreter that has all of the normal additional features that you'd expected of a well-developed command-line interpreter (such as tab completion), but there's also a keyboard shortcut for just running code in a fresh window. I suggest trying it
|
# ? May 1, 2013 06:01 |
|
dantheman650 posted:I am completely new to programming and am playing around with Python after learning some basics on CodeAcademy. I tried using Notepad++ on a friend's recommendation but it turns out getting Python code to run from it is a pain. The OP of this thread is mostly going over my head and the tutorial on setting up VIM is much more advanced and complicated than anything I need at this point. What is a good, simple IDE to write and run Python code? The wiki has a huge list and I don't know which to pick. A lot of people here, myself included, seem to love Sublime Text 2.
|
# ? May 1, 2013 06:42 |
|
dantheman650 posted:I am completely new to programming and am playing around with Python after learning some basics on CodeAcademy. I tried using Notepad++ on a friend's recommendation but it turns out getting Python code to run from it is a pain. The OP of this thread is mostly going over my head and the tutorial on setting up VIM is much more advanced and complicated than anything I need at this point. What is a good, simple IDE to write and run Python code? The wiki has a huge list and I don't know which to pick. Run scripts with alt+shift+f5, or ctrl+alt+shift+f5 for GUI-only.
|
# ? May 1, 2013 11:12 |
|
QuarkJets posted:^^^ Because he's probably in Windows and the Windows command line is ghetto as hell Precisely. Thanks for all the information. Spyder 2 won't install - it gives me a cannot install error "No Python installation found in the registry" I downloaded the Notepad++ plugin and I have no idea what to do with it. The installation guide says to copy to the Notepad++ directory but should I copy and replace the plugin folder that is already there? Sublime Text 2 seems to be working just fine though. I guess that's what I'll be sticking with for now since it's the only one I can get to work! EDIT: I Feel like a complete dummy, but I am getting an EOF error when using the input function. A cursory Google search led me to a few discussions about this, and one of the users wrote: "When running a program within Sublime Text 2, stdin will not be connected to anything (where would you type it?), so this behavior is expected." It appears as if people have had to build their own plugins just to get input to work. Is there any basic, simple editor that will just allow me to write and run Python code without all this hassle? I'm not making anything complex here, just extremely simple stuff to practice my basic skills. Harriet Carker fucked around with this message at 21:06 on May 1, 2013 |
# ? May 1, 2013 20:28 |
|
If all else fails, you can just write scripts and run them from the Python interactive command-line interpreter using import. You will want to add the directory where you are saving the scripts to your PYTHONPATH so that Python can find them. (On my version of Windows I can do this by going Control Panel -> Classic View -> System -> Advanced system settings -> Advanced -> Environment Variables and adding/editing the PYTHONPATH variable under "System variables".)
|
# ? May 1, 2013 21:08 |
|
I don't think there's a lot to be gained in running code inside an editor. This dev configuration works on any platform:
One advantage of this method is that your test environment (the OS shell) is the same as your production environment. So if you have any weird crap like stdin not being connected it's not just a test environment problem it's a real problem you actually need to solve for production.
|
# ? May 1, 2013 21:22 |
|
Hammerite posted:If all else fails, you can just write scripts and run them from the Python interactive command-line interpreter using import. You will want to add the directory where you are saving the scripts to your PYTHONPATH so that Python can find them. (On my version of Windows I can do this by going Control Panel -> Classic View -> System -> Advanced system settings -> Advanced -> Environment Variables and adding/editing the PYTHONPATH variable under "System variables".) OK, I've done this. Dren posted:I don't think there's a lot to be gained in running code inside an editor. This dev configuration works on any platform: All right. So I wrote my script in Notepad++ and am trying to run it in the Python shell (is this the correct terminology?) and I get this error. I have a feeling I'm doing something really silly, but I'm getting frustrated. Edit: Realized I had the path set incorrectly. Changed it to C:\Users\Dan\Desktop\Programs and still getting the same syntax error. Harriet Carker fucked around with this message at 21:45 on May 1, 2013 |
# ? May 1, 2013 21:39 |
|
You are already using the Python interactive interpreter, you are not using the OS's command line. You need to type Python commands, not commands that would be understood by Windows's command line. So to run the code in hello.py you need to type "import hello.py" "python hello.py" is not valid Python syntax, which is why you see that error.
|
# ? May 1, 2013 21:44 |
|
Hammerite posted:You are already using the Python interactive interpreter, you are not using the OS's command line. You need to type Python commands, not commands that would be understood by Windows's command line. So to run the code in hello.py you need to type "import hello.py" I just tried that and I am getting this error (although I do notice it ran the script before producing the error):
|
# ? May 1, 2013 21:47 |
|
I realised that the correct version of the command is "import hello" (without the .py). However, I do not know whether that is the cause of your most recent error message. Try "import hello" and see whether that works better.
|
# ? May 1, 2013 21:51 |
|
Hammerite posted:I realised that the correct version of the command is "import hello" (without the .py). However, I do not know whether that is the cause of your most recent error message. Try "import hello" and see whether that works better. Well, no errors this time! However, it also had no output of any sort.
|
# ? May 1, 2013 21:51 |
|
Hammerlite misspoke. The .py is implied when you import something, so you can leave it off. What might be a lot easier for you, especially considering that it takes some effort to reload a module that's been imported, is to run python through the command interpreter. You can just hit Start and type cmd to get it to come up in the search list. Then, I think you can just run you files by typing python <file path with .py>, assuming it's on the PATH, which you evidently already know how to edit. If you CHDIR to the directory your scripts live (chdir C:\Users\Dan\desktop) you can just type python hello.py to run your scripts.
|
# ? May 1, 2013 21:52 |
|
dantheman650 posted:Well, no errors this time! However, it also had no output of any sort. This is probably because you entered the command in the same command-line window as before, and the hello module had been imported already. Once a module has been imported once, importing it again only serves to define variable names in the namespace in which the import statement appears. If you use "reload hello" you will see output, because that re-executes the script in full. edit: You should probably not get used to using reload, because once you are writing larger scripts that themselves import other scripts of yours, using reload will only re-execute the named script, and not the others nested inside. This is a downside to using the interactive command line. Hammerite fucked around with this message at 22:02 on May 1, 2013 |
# ? May 1, 2013 21:56 |
|
Munkeymon posted:Hammerlite misspoke. The .py is implied when you import something, so you can leave it off. Are you talking about the Windows command prompt or the cmd.py that is in my Python intall directory? If the former, I get an error that it is not recognized as an intrernal or external command. If the latter, it pops open for a second and then immediately closes. A friend I'm chatting with recommended changing my script to a function: def hi(): print ("Hello") Then in the terminal doing: import hello hello.hi() This also did not work, just for the record, and produced "AttributeError: 'module' object has no attribute 'hi'" EDIT: Hammerite posted:This is probably because you entered the command in the same command-line window as before, and the hello module had been imported already. Once a module has been imported once, importing it again only serves to define variable names in the namespace in which the import statement appears. If you use "reload hello" you will see output, because that re-executes the script in full. I closed the terminal, and typed "import hello" on a fresh line. Success! Thank you for your assistance and patience. Another question now: So I type import hello, and it runs and outputs "Hello." Now I go into Notepad++, add another line "print ("Hi")" and save it. I have already imported hello, so do I need to close and reopen the terminal to run my updated code? Harriet Carker fucked around with this message at 22:08 on May 1, 2013 |
# ? May 1, 2013 22:01 |
|
I was advocating that you open two terminals. I suggest that you do not make importing your program your normal means of executing your program. To get the first terminal (for executing your program) do this:
You may then edit your program with the editor of your choice and rerun it by typing 'python hello.py' again. To get the second terminal (python interpreter for testing stuff) do this:
In this second terminal you'll be able to do stuff like quickly test a one liner or figure out what that method for making a string lowercase is: code:
Dren fucked around with this message at 22:10 on May 1, 2013 |
# ? May 1, 2013 22:08 |
|
dantheman650 posted:Are you talking about the Windows command prompt or the cmd.py that is in my Python intall directory? Use the [ code ] tags when posting code, because otherwise people who read your post may not see spacing correctly. This is particularly important for Python because whitespace is syntactically significant. Did you close and reopen the interpreter, or use reload, as I mentioned? You might be getting that error from the Windows command line because Python is not in your PATH and so Windows can't find it. Follow the same steps you used to edit the PYTHONPATH variable but this time change the PATH variable (it might be capitalised differently) by adding the path to the directory where python.exe is at the end, after a semicolon.
|
# ? May 1, 2013 22:09 |
|
Dren posted:I was advocating that you open two terminals. I suggest that you do not make importing your program your normal means of executing your program. This works perfectly. Thank you again for your patience and clear explanations. Hammerite posted:Use the [ code ] tags when posting code, because otherwise people who read your post may not see spacing correctly. This is particularly important for Python because whitespace is syntactically significant. I didn't know about the code tag! I will use it in the future. Closing and reopening the interpreter worked fine, and I didn't use reload since you warned against it. I added the Python directory to PATH and am still getting that error if I first don't CD to my programs directory, but that's ok - it only takes a second to CD and that works fine for now. I'm going to stop cluttering the thread now and go practice!
|
# ? May 1, 2013 22:16 |
|
dantheman650 posted:I added the Python directory to PATH and am still getting that error if I first don't CD to my programs directory, but that's ok - it only takes a second to CD and that works fine for now. You added PYTHONPATH so you can type 'python' in command line. When you do 'python hello.py' cmd knows wheres python, but not hello.py. Thats why you need to cd to your script path first. Alternatively, you can specify full path like so: 'python c:\dev\hello.py'. You can do [ code=python ] for proper python syntax highlighting. evilentity fucked around with this message at 23:41 on May 1, 2013 |
# ? May 1, 2013 23:39 |
|
dantheman650 posted:I downloaded the Notepad++ plugin and I have no idea what to do with it. The installation guide says to copy to the Notepad++ directory but should I copy and replace the plugin folder that is already there? Dominoes fucked around with this message at 00:08 on May 2, 2013 |
# ? May 2, 2013 00:00 |
|
Can someone write me a base class that provides to_dict and from_dict for a subclass or show me how to reorganize my objects to get this functionality generalized? I have a feeling that maybe what I want is a metaclass but I'm not entirely certain. I guess the thing I feel shaky about is inheritance with the classmethod.Python code:
|
# ? May 2, 2013 16:11 |
|
I think all you actually have to do is change code:
code:
And the from_dict will work just fine as is, unless you want your subclass to have extra fields and the to_dict to return those. But you could just iterate through self.fields instead.
|
# ? May 2, 2013 16:39 |
|
Worked perfectly, thanks. That cls() will construct an instance was the piece I was forgetting.
|
# ? May 2, 2013 17:13 |
|
Dren posted:generalized behavior... This will allow you to reuse the code. Python code:
|
# ? May 2, 2013 18:43 |
|
Thanks, that's almost exactly what I ended up writing. Even called it Dictable.
|
# ? May 2, 2013 19:01 |
|
I just found out that setup.py will make an rpm for you. That is beyond awesome.
|
# ? May 2, 2013 21:50 |
|
I'm trying to make a drop-out stack, I.E. the bottom element of the stack is "deleted" when you push an element after the stack is full. The code I have so far is basically just a default stack, but I tried to modify the push method so that when you push a number of elements larger than the "max size" of the stack, it instead will make the node pointing point to the last node point 2nd to last node instead. What I have here doesn't cause any changes to the output and I'm kind of stuck on where to go from here.code:
|
# ? May 3, 2013 05:34 |
|
Qwertyiop25 posted:
I'm curious what you think this is going to do.
|
# ? May 3, 2013 06:36 |
|
Qwertyiop25 posted:
I think you might also have a few problems here. I'm guessing self.top == self.n should be self.size == self.n? And I'm figuring that you meant to decrement size (or hold off incrementing it) when you reached the stack's size limit, and also that you meant to have an assignment in that last line, instead of a comparison. ...And I'm going to guess that self.top = self.top.next.next isn't going to do what you want the stack to be doing. Extortionist fucked around with this message at 08:54 on May 3, 2013 |
# ? May 3, 2013 08:40 |
|
Qwertyiop25 posted:I'm trying to make a drop-out stack, I.E. the bottom element of the stack is "deleted" when you push an element after the stack is full. c.f ring buffers? quote:def isEmpty(self): instead of the Javaesque isEmpty, you could instead provide a __bool__ method. Or perhaps you can do the following. code:
|
# ? May 3, 2013 10:58 |
|
dantheman650 posted:This works perfectly. Thank you again for your patience and clear explanations. Python on Windows comes bundled with an IDE (Idle) as well as a commandline shell environment and I would seriously just use those. Both are literally in its start menu folder. If you are using Windows 8 I am sorry for your lots. As an alternative, I would recommend PyDev for Eclipse even though Eclipse is a terrible program and PyDev is an Smarmy Coworker fucked around with this message at 19:10 on May 3, 2013 |
# ? May 3, 2013 18:09 |
|
ARACHNOTRON posted:Python on Windows comes bundled with an IDE (Idle) as well as a commandline shell environment and I would seriously just use those. Both are literally in its start menu folder. If you are using Windows 8 I am sorry for your lots. If you're looking for autocomplete, Sublime Text 2 is much nicer than Eclipse, without the unnecessary bloat. It has some great Python plugins. Also, it's the best text editor in the universe.
|
# ? May 3, 2013 19:04 |
|
Honestly I just use gedit and VIM most of the time but that editor looks really rad and I might at least download it. I don't know if I can deal with ctrl+D not being Delete Line though
|
# ? May 3, 2013 19:14 |
|
ARACHNOTRON posted:Honestly I just use gedit and VIM most of the time but that editor looks really rad and I might at least download it. Aquamacs.
|
# ? May 3, 2013 19:20 |
|
ARACHNOTRON posted:Honestly I just use gedit and VIM most of the time but that editor looks really rad and I might at least download it. The keybinds (and preferences) are just JSON files so you can tweak that however you like. Furthermore, it has a 'Vintage' mode which basically works like VIM with Command and Insert mode. And if you don't jizz in your pants the first time you do multiple simultaneous edits, you have no soul.
|
# ? May 3, 2013 20:49 |
|
What do you mean multiple simultaneous edits?
|
# ? May 3, 2013 21:16 |
|
Dren posted:What do you mean multiple simultaneous edits? You can edit multiple parts of the same file simultaneously. You can see it in action here: http://www.sublimetext.com/ Here's an example of it in Visual Studio via an extension: http://www.hanselman.com/blog/SimultaneousEditingForVisualStudioWithTheFreeMultiEditExtension.aspx
|
# ? May 3, 2013 21:56 |
|
|
# ? May 9, 2024 05:16 |
|
This is multi-selection editing: Smart rearrange is also awesome:
|
# ? May 3, 2013 21:59 |