|
If I wanted to dabble in making computer generated images pixel by pixel and applying changes via a program, is there any modules like that in Python? Like say I wanted to make a png where the top left pixel was red, the next one over in the same row was green, etc. I realize I dont know what I really want here, but I want something fairly low level.
|
# ? Jun 1, 2012 17:11 |
|
|
# ? Jun 12, 2024 05:13 |
|
There's PIL, but it's old and outdated and silly, and has a bad API in my opinion. You can also try things like cairo, of course, which can write image surfaces to PNGs. Last I checked, pycairo could do pixel-level access.
|
# ? Jun 1, 2012 17:21 |
|
Sylink posted:If I wanted to dabble in making computer generated images pixel by pixel and applying changes via a program, is there any modules like that in Python? the PIL is the standard here, and you can use something like Image.putpixel to do this e: or cairo would be reasonable as well, since the PIL does have its downsides No Safe Word fucked around with this message at 17:25 on Jun 1, 2012 |
# ? Jun 1, 2012 17:23 |
|
Kungfoomasta posted:where src is the file including path. I thought that including the "rb" in open(src,'rb') meant to read it in as binary, but maybe I'm doing it wrong - does anyone know why this doesn't work? Don't use print, it adds additional newlines that might screw up the data. Also HTTP requires you to use \r\n as terminator, not \n. Do code:
Cat Plus Plus fucked around with this message at 17:27 on Jun 1, 2012 |
# ? Jun 1, 2012 17:24 |
|
PiotrLegnica posted:Don't use print, it adds additional newlines that might screw up the data. Also HTTP requires you to use \r\n as terminator, not \n. Do Brilliant! I wound up with this: code:
|
# ? Jun 1, 2012 18:33 |
|
When I use PIL if I have to any manipulation, I find it's a lot easier to convert it to a numpy array first and then mess around, and then cast it back.Python code:
|
# ? Jun 1, 2012 22:56 |
|
Python 3.3 alpha release notes out and give clues to what is going in to the next release. What I'm most excited about :
|
# ? Jun 2, 2012 02:44 |
|
Hed posted:PEP 3144 IP address class is going in. The reference implementation that appears to be used for that PEP doesn't support valid IPv4 addresses such as "1.2" and "1.2.3456". Because, as it turns out, everybody who reimplements IPv4 address parsing gets it wrong and I don't know why people keep trying when the standard C library provides perfectly good functions for doing this.
|
# ? Jun 2, 2012 03:59 |
|
Hed posted:Python 3.3 alpha release notes out and give clues to what is going in to the next release. Oh man they dropped vms support
|
# ? Jun 2, 2012 04:44 |
|
Still doesn't have bytes.format
|
# ? Jun 2, 2012 05:06 |
|
Hey, I'm hoping this will be a short question but I'm not really sure. I have this framework for Actions in my django app that is a Django Model called Action, subclassed by proxy Model that define different actions and how to do and undo them. The base class Action acts as a dispatcher, called like with Action.do_action('import_path', source_of_action, [arguments]). It processes the import path with the __import__ function. It's been working peachy thus far but my actions.py files have been getting heavy so I want to rework them into a directory structure ie code:
Python code:
Neither action module imports the other, only subclassing Action. It feels like I should be able to make this work but maybe I've just coded myself into a corner here.
|
# ? Jun 3, 2012 06:43 |
|
Don't try to be clever and use __import__. Is there something wrong with explicitly importing an action?
|
# ? Jun 3, 2012 06:57 |
|
I need the path saved into the database, so that whatever Action I use, when I later do something like:Python code:
Python code:
|
# ? Jun 3, 2012 07:18 |
|
Good job coupling your data to your code, there. Surely any future refactors aren't going to break your database entirely. As for the import problem, I don't know why this is happening. I'd have to see the actual code.
|
# ? Jun 3, 2012 07:36 |
|
ShoulderDaemon posted:The reference implementation that appears to be used for that PEP doesn't support valid IPv4 addresses such as "1.2" and "1.2.3456".
|
# ? Jun 3, 2012 07:36 |
|
Suspicious Dish posted:Good job coupling your data to your code, there. Surely any future refactors aren't going to break your database entirely. edit: Anyhow, I'm just gonna reorganize my package structure a different way, no point butting my head against a brick wall aver this one. Maluco Marinero fucked around with this message at 09:06 on Jun 3, 2012 |
# ? Jun 3, 2012 08:04 |
|
Scaevolus posted:How are those addresses valid? IPv4 addresses are made of 1 to 4 numbers, separated by periods. All numbers but the last must be from 0 to 255, and represent the higher-order bytes of the address. The last number represents all remaining bytes of the address. This is handy when you are in a network with zeroes in the middle of its addresses, because you can compress them away. 192.168.0.1 == 192.168.1 == 192.11010049 == 3232235521 10.0.0.1 == 10.0.1 == 10.1 == 167772161 8.8.8.8 == 8.8.2056 == 8.526344 == 134744072 If you get in the habit of typing your gateway as "10.1" and then suddenly have to deal with a program that wrongly insists that isn't a valid IPv4 address, it's sort of annoying.
|
# ? Jun 3, 2012 21:55 |
|
ShoulderDaemon posted:IPv4 addresses are made of 1 to 4 numbers, separated by periods. All numbers but the last must be from 0 to 255, and represent the higher-order bytes of the address. The last number represents all remaining bytes of the address. I knew you could go full decimal or dotted bytes, but I didn't know there was anything in between. Neat!
|
# ? Jun 4, 2012 00:26 |
|
ShoulderDaemon posted:If you get in the habit of typing your gateway as "10.1" and then suddenly have to deal with a program that wrongly insists that isn't a valid IPv4 address, it's sort of annoying. Like Chrome? I had no idea this was a thing and when I tried it in Chrome it just searched for it instead of sending me to 127.1
|
# ? Jun 4, 2012 01:46 |
|
OnceIWasAnOstrich posted:Like Chrome? I had no idea this was a thing and when I tried it in Chrome it just searched for it instead of sending me to 127.1 I don't use Chrome, so I wouldn't really know. Firefox supports it, uzbl (the only webkit browser I have installed) supports it, anything that uses the libc resolver supports it. Edit: The definitive test is probably the ping program. On both Windows and Linux you can ping 127.1, so any web browser that doesn't let you attempt to connect to 127.1 has a bug. ShoulderDaemon fucked around with this message at 02:22 on Jun 4, 2012 |
# ? Jun 4, 2012 02:20 |
|
OnceIWasAnOstrich posted:Like Chrome? I had no idea this was a thing and when I tried it in Chrome it just searched for it instead of sending me to 127.1
|
# ? Jun 4, 2012 03:21 |
|
http://1249763762 works too.
|
# ? Jun 4, 2012 03:28 |
|
Can anyone recommend a Django book? The official docs are good, but I always like to read someone elses detailed take to help fill in the gaps and sometimes when something is explained in a different way it makes more sense...
|
# ? Jun 4, 2012 03:52 |
|
Thermopyle posted:Can anyone recommend a Django book?
|
# ? Jun 4, 2012 05:17 |
|
I really enjoyed Pro Django as it goes into detail about the inner workings far better than the docs and it gives that alternate perspective that you noted. For someone like you who understands Python first, I think it would be an excellent book. Its downside is much like the other books in the Django world--it is a few years old and only covers 1.1-1.2, missing things like Class-based Generic Views and Mixins. The official docs cover the former and for the latter turn to our very own MonkeyMaker for some great examples.
|
# ? Jun 4, 2012 05:26 |
|
Oh hey, there's a Django thread. Thanks for your answers, you two.
|
# ? Jun 4, 2012 05:46 |
|
PyAudio is going to be the death of me. I somehow got it to compile on Lion after much effort, but then I try to install PyAudio and it barfs this at me.
|
# ? Jun 4, 2012 07:16 |
|
You need to install PortAudio headers, it looks like.
|
# ? Jun 4, 2012 08:05 |
|
I'm trying to install python-MySQL inside a virutalenv on OS X 10.7 I upgraded XCode and downloaded the command line tools as suggested in various google results. Now when I try "pip install MySQL-python" I get a ton of _mysql.c errors, finishing with: quote:llvm-gcc-4.2: error trying to exec '/usr/bin/../llvm-gcc-4.2/bin/powerpc-apple-darwin11-llvm-gcc-4.2': execvp: No such file or directory There are hardly any google results for that last line, so I've no idea what the problem is. Any ideas what the problem could be? edit: Could the bit referring to "powerpc-apple-darwin11-llvm-gcc-4.2" be the problem? It's an Intel Mac so I don't know why it has anything referring to PowerPC. ryo fucked around with this message at 11:00 on Jun 4, 2012 |
# ? Jun 4, 2012 10:38 |
|
ryo posted:I'm trying to install python-MySQL inside a virutalenv on OS X 10.7 http://stackoverflow.com/questions/6839795/cant-figure-out-the-architecture-type-of-problem-when-compiling-python
|
# ? Jun 4, 2012 18:14 |
|
Hey guys. I am learning the fundamentals of python currently and, to get started, I am attempting to make a simple 'packman' game in vizard (a python based game engine/IDE) While attempting to test out class inheritance, I have come across an error that I cannot seem to fix. I have gone over every inch of my code and I cannot understand where the error is coming from: code:
code:
I'm completely new to python so I know it's going to be something stupid, but I've been stuck for over an hour. Thanks in advance to anyone who can help. Kosani fucked around with this message at 21:00 on Jun 4, 2012 |
# ? Jun 4, 2012 20:56 |
|
What is an __init__self?
|
# ? Jun 4, 2012 21:01 |
|
Suspicious Dish posted:What is an __init__self? Ah. Wow. That was dumb of me. Thank you.
|
# ? Jun 4, 2012 21:08 |
|
Any ideas why this isn't working? It's a 407kb bmp, but it only seems to be reading the first ~160 bytes. code:
edit: figured it out. There was an EOF character in there; needed to use 'rb' when opening. Also second anticipated problem: Suppose I am eventually able to load in the file and get a nice 407kb string. What is the best way to sum the elements mod 100? Thanks! FrozenShellfish fucked around with this message at 23:37 on Jun 5, 2012 |
# ? Jun 5, 2012 23:35 |
|
What are the elements? Bytes? sum(ord(c) for c in contents) % 100
|
# ? Jun 6, 2012 00:20 |
|
FrozenShellfish posted:Also second anticipated problem: Suppose I am eventually able to load in the file and get a nice 407kb string. What is the best way to sum the elements mod 100? If you've got numpy, it's easy to go Python code:
Python code:
|
# ? Jun 6, 2012 00:24 |
|
Ridgely_Fan posted:When I use PIL if I have to any manipulation, I find it's a lot easier to convert it to a numpy array first and then mess around, and then cast it back. Also, you can just use numpy to cast your image array a float datatype, which lets you do awesome and surprisingly simple stuff like auto-equalizing and tone mapping.
|
# ? Jun 6, 2012 00:36 |
|
Python code:
Bash code:
Any idea how I make it stop doing this to me? I'd rather not just encode the string as UTF-8 before outputting it, I just want it to use the appropriate locale settings even when it's not writing to a pty. EDIT: urgh, found the answer, which is to do this: Python code:
Zombywuf fucked around with this message at 14:45 on Jun 6, 2012 |
# ? Jun 6, 2012 14:31 |
|
Zombywuf posted:Why are you doing this to me Python? sys.stdout is opened without an encoding when you pipe. quote:Damnit Guido!
|
# ? Jun 6, 2012 15:36 |
|
|
# ? Jun 12, 2024 05:13 |
|
Here's a total newbie question How do I create a list of some given size populated with all the same element? Basically Python code:
|
# ? Jun 6, 2012 19:00 |