|
diddy kongs feet posted:Total programming rookie, working on an assignment in jython and I'm trying to implement input validation for two things at once, kinda stumped. Basically I'm drawing a 'room' on an image and then requesting input location to place a light inside the room. Between taking inputs and placing the light I want to check that the x/y coords are within the image and that the light is actually placed inside the room I've drawn. I can validate both of these independently just fine but can't work out a good economy for doing both appropriately, since my logic so far lets the user pass one check and then fail the first check when passing the second yet continue. I know how to wing it but I'd be repeating a lot of code and that doesn't seem right to me. Are you familiar with finite state machines? This abstraction might help you deal with validating input through states.
|
# ? May 16, 2014 15:42 |
|
|
# ? May 20, 2024 06:25 |
|
drat thanks loads, great reading. I probably should've gone back and edited in that I managed to work out a rough logic for my validation so it's working for now, I guess my post was more a cry for help re: background reading, 'best practice' reading etc. What's the consensus on jython anyway? Some grads I spoke to were talking trash on this intro programming class for using JES but as a beginner it's been good stuff. How well does it lead into vanilla python? Where's a good place to start if I want to get a head start on it? Went through all the OP links but further reading is always appreciated.
|
# ? May 16, 2014 16:52 |
|
diddy kongs feet posted:drat thanks loads, great reading. I probably should've gone back and edited in that I managed to work out a rough logic for my validation so it's working for now, I guess my post was more a cry for help re: background reading, 'best practice' reading etc. I'm not familiar with jython at all, but from briefly perusing the google results for "difference jython python", it seems like you could drop right into using CPython right now. In other words, the answer to "How well does it lead into vanilla python?" seems like "Almost perfectly".
|
# ? May 16, 2014 17:29 |
|
As long as you don't care about using new language features (last time I used jython it implemented python 2.6), and don't care about C extensions then cPython and jython are basically identical from a programmer perspective.
|
# ? May 16, 2014 18:00 |
|
Anyone have anything I can read about anydbm and how it works? If I care about how it works is that a sign that I should actually pick a db engine?
|
# ? May 16, 2014 18:17 |
|
Its just an interface to whatever random dbm implementation it decides to grab. I tried using it the other day on OSX and it combined with whatever ancient BSD dbm it comes with caused my computer to hard reboot whenever I ran my script. I started using Kyoto Cabinet and never looked back. edit: For a little more detail. You can think of anydbm and all of the specific varieties as on-disk dictionaries. They all utilize various versions/implementations of dbm which is a non-relational database/key-value store. You would use anydbm if you need to use something kind of like a dictionary without keeping it all in memory, and you need this something to be in the standard library. OnceIWasAnOstrich fucked around with this message at 18:53 on May 16, 2014 |
# ? May 16, 2014 18:32 |
|
OnceIWasAnOstrich posted:Its just an interface to whatever random dbm implementation it decides to grab. I tried using it the other day on OSX and it combined with whatever ancient BSD dbm it comes with caused my computer to hard reboot whenever I ran my script. I started using Kyoto Cabinet and never looked back. ok thanks, that's enough information to know it's not what I want.
|
# ? May 16, 2014 18:55 |
|
Have you looked at the standard library shelve module?
|
# ? May 16, 2014 19:03 |
|
Trying to clean up some data again. I'm getting output like this from a website:Python code:
Python code:
Because doing a str.replace() leaves me with: Python code:
the fucked around with this message at 19:18 on May 16, 2014 |
# ? May 16, 2014 19:13 |
|
It sounds like you just want to keep newline returns, so don't replace those. Just replace \t and see what it looks like. If you need to grab specific pieces, then you could use string.split('\r\n')
|
# ? May 16, 2014 19:35 |
|
QuarkJets posted:It sounds like you just want to keep newline returns, so don't replace those. Just replace \t and see what it looks like. If you need to grab specific pieces, then you could use string.split('\r\n') So the \r\n is a newline return? How come it's not displaying that way?
|
# ? May 16, 2014 19:52 |
the posted:So the \r\n is a newline return? How come it's not displaying that way? It's platform dependent: http://en.wikipedia.org/wiki/Newline
|
|
# ? May 16, 2014 20:02 |
|
Can you try a regex filter like this:code:
edit: The regex \\\D means match if any non-digit character has a \ in front of it. The first slash in '\\' means escape. So \\ means match a '\'. \D means match any non-digit. namaste friends fucked around with this message at 20:11 on May 16, 2014 |
# ? May 16, 2014 20:06 |
|
Cultural Imperial posted:Can you try a regex filter like this: Did you try this? Those backslashes aren't actually in the string. They're only in the output of str.__repr__ -- known control characters are dumped as backslash escapes.
|
# ? May 16, 2014 21:02 |
|
Lysidas posted:Did you try this? Those backslashes aren't actually in the string. They're only in the output of str.__repr__ -- known control characters are dumped as backslash escapes. I tried it in the tester and in code, although I admit I didn't spend a lot of time on it. Apologies since I'm completely wrong.
|
# ? May 16, 2014 21:12 |
|
I wanted to take cocos2d for a spin, since the last version is supposed to be compatible with Python 3. So far it refuses to recognise it as a package. Is there some trick to installing it, or am I just being dumb about it?
|
# ? May 16, 2014 22:58 |
|
Lichtenstein posted:I wanted to take cocos2d for a spin, since the last version is supposed to be compatible with Python 3. So far it refuses to recognise it as a package. What are you doing now? I would assume that you are doing "pip3 install cocos2d", or perhaps "python3 setup.py install".
|
# ? May 17, 2014 00:04 |
|
Yep, tried both of those. I've installed both pyglet 1.2 and six, so it shouldn't be related to dependency shenanigans.
|
# ? May 17, 2014 00:16 |
|
Lichtenstein posted:Yep, tried both of those. I've installed both pyglet 1.2 and six, so it shouldn't be related to dependency shenanigans. Can you show a traceback?
|
# ? May 17, 2014 00:43 |
|
When I tried to do the hello world straight from the docs it throwscode:
code:
|
# ? May 17, 2014 01:11 |
|
the posted:Trying to clean up some data again. I'm getting output like this from a website: Regex is way too much work. Try io.StringIO with newline=None for universal newline mode. code:
BigRedDot fucked around with this message at 01:40 on May 17, 2014 |
# ? May 17, 2014 01:32 |
|
Lichtenstein posted:When I tried to do the hello world straight from the docs it throws What version of setuptools do you have? Run pip list to find out.
|
# ? May 17, 2014 03:36 |
|
Do you know a way I could combine/append two lxml.html.HtmlElement objects? Like say I read from a page and I wanted to grab/work with tables[5] and tables[7] I tried: Python code:
edit: this worked: Python code:
the fucked around with this message at 20:40 on May 19, 2014 |
# ? May 19, 2014 20:29 |
|
I'm failing at figuring out how to display a line of text that includes values from two lists in a certain way (two values, then a separator, then two more values etc)code:
The users are Adam (20), Ben (30), Bob (40) I'm trying to get this to work using zip but the closest I've come so far is: code:
|
# ? May 21, 2014 18:34 |
|
andyf posted:I can't figure out how to make it only do the ", " join after a value from each list has been used, rather than after each single value. Any ideas? You are asking it to do a single type of join (', ') on a single list when you want two different types of joins (', ' and ' '). Instead of flattening your list of tuples you get from zip() in that awful nested comprehension you need to do a ' '.join() on each name/value tuple in the list. Python code:
OnceIWasAnOstrich fucked around with this message at 18:42 on May 21, 2014 |
# ? May 21, 2014 18:39 |
|
Ahhhhh great, thank you!
|
# ? May 21, 2014 18:46 |
Is there a better way to extract the number out of a string like 'file[0]' ?Python code:
|
|
# ? May 21, 2014 20:10 |
|
Why do you want to?
|
# ? May 21, 2014 20:46 |
Suspicious Dish posted:Why do you want to? Why do I want to find a better way? Just wanted to make sure the way I'm doing it isn't totally stupid or Why do I want to get the number out of that string? Django's request.FILES has 'file[0]' as the key, and I need to grab the corresponding caption from request.DATA.getlist('caption')
|
|
# ? May 21, 2014 20:49 |
|
fletcher posted:Is there a better way to extract the number out of a string like 'file[0]' ? Wel if you want to get more specific with the regex: Python code:
(I didn't actually test the code, typing on a tablet sorry)
|
# ? May 21, 2014 22:52 |
|
How would I do this? "for row in b: but skip the first row"
|
# ? May 22, 2014 17:48 |
the posted:How would I do this? Python code:
|
|
# ? May 22, 2014 17:55 |
|
for row in b[1:] etc...?
|
# ? May 22, 2014 17:57 |
|
Alternatively, if b is an iterator, just call code:
|
# ? May 22, 2014 17:58 |
|
In case anyone was curious, I'll post the problem I was having. I am trying to grab the information from this page. My code looked like this:Python code:
However, I printed out the last entry before it crashed, and it was the entry of Jenkins Aquarium. If you notice, that one doesn't have it's own url entry, meaning that the links list was only 2 entries long for that one (while the rest were 3). So I fixed it by changing links[3] to links[-1].
|
# ? May 22, 2014 18:25 |
|
Crossposting from the scientific computing thread...SurgicalOntologist posted:I decided to use software-carpentry's setup instructions for my scientific computing workshop that's starting next week. This uses Anaconda, and msysgit on Windows.
|
# ? May 23, 2014 17:08 |
|
Don't use Windows? Alternatively, just call all your environment binaries directly using their path instead of relying on the activate scripts to try to change all of your paths in ways designed for a different type of shell. I don't know of anything that requires you to use the activation scripts, and I hardly ever use them with my environments. The conda command handles environments with a switch, and I call pip/interpreters directly from the environments bin directory. Or I guess you can write your own activate script that does whatever activate scripts use with msys syntax.
|
# ? May 23, 2014 21:17 |
|
SurgicalOntologist posted:Crossposting from the scientific computing thread... activate.bat is a windows batch file, it will only work from cmd.exe or PowerShell. You can use conda and activate.bat perfectly well from these windows native command line tools and that would be my immediate suggestion.
|
# ? May 23, 2014 21:26 |
|
OnceIWasAnOstrich posted:Don't use Windows? If I could convince everyone not to use Windows I would (maybe by the end of the workshop...). Of course I could do a VM or something but I want to leave people with a native solution or they won't ever fire up Python again. The reason I'm using msys is so I can have the same instructions for everyone, once everything is setup. Not a bad idea to just not bother with activating at all, I hadn't really considered that. BigRedDot posted:activate.bat is a windows batch file, it will only work from cmd.exe or PowerShell. You can use conda and activate.bat perfectly well from these windows native command line tools and that would be my immediate suggestion. Yeah the backup plan was to just have Windows users open up both bash and cmd but if I'm going to teach bash basics it would be nice to have everything in one place. Maybe I'll write a bash wrapper around activate.bat. SurgicalOntologist fucked around with this message at 21:30 on May 23, 2014 |
# ? May 23, 2014 21:28 |
|
|
# ? May 20, 2024 06:25 |
|
I taught a learning Python class once with Anaconda and I found everything to be too much work in Windows and unfortunately I never found a good way to make Windows act enough like Unix so I just skipped it and taught the entire class in the Spyder IDE that comes with Anaconda. Not my finest moment, but I wasn't getting paid and didn't want to do any more work than necessary. Why do you need environments at all?
|
# ? May 23, 2014 22:54 |