Re: More & More Fun w/ Pics & MySQL
Hi,
Victor Subervi schrieb:
> Let me clarify. This prints out "all sorts of crap", which means an
> image string, the image as a string, to the screen:
>
> print 'Content-type: image/jpeg'
> print 'Content-Encoding: base64'
> print
> print pic().encode('base64')
> print ''
>
> The following once upon a time printed images, but now it doesn't. Why
> would that be? I would refresh the screen, and it would print. I'd
> change a line and it wouldn't. I'd change it back to what it was and it
> would no longer the image to the screen. Why is that? The same happens
> with or without the base64 stuff. Commenting out a line seemed to make a
> difference!
>
> print 'Content-type: text/plain'
> #print 'Content-type: image/jpeg'
> print
> print pic()
> print ''
>
> The above prints out a broken image of correct dimensions.
Only with a broken client (I assume Internetexplorer here?)
Any you don't know what it does in guessing and caching (Try
shift-reload when you test things)
You should work from a static page and a static image and look what
is transferred by the server (wireshark or tcpflow are of great help,
but nc | hexdump -C | more is probably more easy if you work out the
HTTP protocol (see rfc2616)
You script needs to do the same as a server would do serving a static
resource. Just look how it works and rebuild it.
You will quickly find out, that there is obviously no reason to have
at the end of a binary resource an Image is.
Also correct mime type is important unless you deal with broken clients.
There are a lot more HTTP-Headers you want to understand and use but the
simple usage above, provided pic() indeed returns the binary data of the
image unaltered, should work (w/o the html crap at the end).
You would not use print since it adds a linefeed at the end which is not
part of the data. sys.stdout.write() should work better (and can be used
incremental to avoid returning the whole image data from memory)
> Of course I try and figure out how things work once they get working.
> Sometimes, however, there is __no__ logic to it __at__all__. Sorry.
> After years of struggling with python I've come to realize that even
> though I may not be a good programmer, it isn't me. It may not be python
> itself. It may be the crappy hardware the server farms use. It may be
> the way they tweak their python interpreter. But it isn't just me.
Sorry to tell you that but its just you. There is no magic in that.
Ok, there is one thing: what makes you sure the data in the database
is really unaltered image data? I mean, you are using mysql...
for a first thing I'd write the output into a file and try to open it
in a graphic viewer.
> It would be nice if I could get this code printing images to the screen
> as it was before I had to put out another unnecessary fire when code
Images are not "printed to screen" the whole idea is just wrong.
> that previously uploaded the images in the first place inexplicably no
> longer worked. Then, lo and behold, when I came back to this code that I
> hadn't touched and was working fine earlier this week, it no longer
> works. Lovely. My "plug-and-play" program has devoured two weeks of my
> time and I'm still up the creek without a paddle. Sure would appreciate
> any help you can give.
I see "plug and play" and read cargo-cult. You need to read a bit about
the basics on the matter or you will constantly run uphill - and even if
it seems to work it has no value if you don't know _why_.
Regards
Tino
--
http://mail.python.org/mailman/listinfo/python-list
Re: Beginning Question about Python functions, parameters...
astral orange schrieb:
> Hi, I am trying to teach myself Python and have a good book to help me
> but I am stuck on something and I would like for someone to explain
> the following piece of code for me and what it's actually doing.
> Certain parts are very clear but once it enters the "def store(data,
> full_name): " function and the "def lookup()..." function things
> get a little confusing for me. Specifically, lines 103-108 *and* Lines
> 110-111.
>
> Lastly, I am not sure how to print the results I've put into this
> program either, the book I'm reading doesn't tell me. As you can tell,
> I am a beginner and I don't truly understand everything that is going
> on here...a lot, but not all
>
> Here is the code:
>
> 92 def init(data):
> 93 data['first'] = {}
> 94 data['middle'] = {}
> 95 data['last'] = {}
> 96
> 97 def store(data, full_name):
> 98 names = full_name.split()
> 100 if len(names) == 2: names.insert(1, '')
> 101 labels = 'first', 'middle', 'last'
> 103 for label, name in zip(labels, names):
> 104 people = lookup(data, label, name)
> 105 if people:
> 106 people.append(full_name)
> 107 else:
> 108 data[label][name] = [full_name]
> 109
> 110 def lookup(data, label, name):
> 111 return data[label].get(name)
> 112
> 113
> 114 MyNames = {}
> 115 init(MyNames)
> 116 store(MyNames, 'John Larry Smith')
> 117 lookup(MyNames, 'middle', 'Smith')
If it tells you so I'm not really sure its a good book - partially for
teaching you into the unpythonic way to do things (above stuff, if its
not a counter example, should really go into a class)
Have you tried the tutorial first? Its online and very easy to follow
from the very beginning but you can also skip parts if you are sure you
already understand it:
http://docs.python.org/tutorial/
HTH
Tino
--
http://mail.python.org/mailman/listinfo/python-list
Re: Anything like "Effective Java" for Python?
I have learned java for half a year and now I want to learn Python, should I learn python 3k or the traditional version? On Wed, Mar 10, 2010 at 7:19 AM, kj wrote: > > > > Subject line pretty much says it all: is there a book like "Effective > Java" for Python. I.e. a book that assumes that readers are > experienced programmers that already know the basics of the language, > and want to focus on more advanced programming issues? > > ~K > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
SIP
Hi All, I was looking at the SIP tool to create a C extensions for python to call. Here is what I tried: 1. I created a simple c file and .h file 2. Then I created a corresponding testfunc.sip file ### %CModule siptest 0 %UnitCode #include"testfunc.h" %End void pyfunc(); %MethodCode func1(); %End 3. I ran SIP on this which generated the following files: sipsiptestpart0.c and sipAPIsiptest.h 4. I then added these generated files along with testfunc.c and testfunc.h in my MS Visual studios solution to create a testsip.dll file 5. Now to call my module from this dll I invoke a script which tries to import my modules. My pythn call is as follows: #code# import siptest I get following error : import error : no module named siptest Please help me find what I am not doing or what mistake am i commiting. -- http://mail.python.org/mailman/listinfo/python-list
Re: SIP
On Apr 9, 10:30 am, Stefan Behnel wrote: > omnia neo, 09.04.2010 07:01: > > > import siptest > > > I get following error : > > import error : no module named siptest > > Is the directory where your siptest.dll lies in your PYTHONPATH (sys.path)? > > Otherwise, Python can't find it. > > Stefan thanks for reply Stefan.. well I added PYTHONPATH = in my environment variables (windows XP). -- http://mail.python.org/mailman/listinfo/python-list
Re: SIP
On Apr 9, 10:42 am, omnia neo wrote:
> On Apr 9, 10:30 am, Stefan Behnel wrote:
>
> > omnia neo, 09.04.2010 07:01:
>
> > > import siptest
>
> > > I get following error :
> > > import error : no module named siptest
>
> > Is the directory where your siptest.dll lies in your PYTHONPATH (sys.path)?
>
> > Otherwise, Python can't find it.
>
> > Stefan
>
> thanks for reply Stefan..
> well I added PYTHONPATH = in my environment variables
> (windows XP).
well I just tried this too.
I added the path using sys.path on the fly in my python script as
follows:
###
import sys
sys.path.append("")
print sys.path
import siptest
###
again same error:
ImportError: No module named siptest.
--
http://mail.python.org/mailman/listinfo/python-list
Re: [Solved] SIP installation and usage on windows
On Apr 9, 7:41 pm, Gabriel Genellina wrote:
> omnia neo gmail.com> writes:
>
>
>
>
>
> > On Apr 9, 10:42 am, omnia neo wrote:
> > > On Apr 9, 10:30 am, Stefan Behnel wrote:
>
> > > > omnia neo, 09.04.2010 07:01:
>
> > > > > import siptest
>
> > > > > I get following error :
> > > > > import error : no module named siptest
>
> > > > Is the directory where your siptest.dll lies in your PYTHONPATH
> (sys.path)?
> > > well I added PYTHONPATH = in my environment variables
> > > (windows XP).
>
> > well I just tried this too.
> > I added the path using sys.path on the fly in my python script as
> > follows:
>
> > ###
> > import sys
> > sys.path.append("")
> > print sys.path
> > import siptest
> > ###
>
> > again same error:
> > ImportError: No module named siptest.
>
> Make sure the extension module must is called siptest.pyd, not
> siptest.dllhttp://docs.python.org/extending/windows.html
> (I'd expect SIP to take care of this)
>
> --
> Gabriel Genellina- Hide quoted text -
>
> - Show quoted text -
SIP tool installation steps are as follows:
• Download latest SIP from:
http://www.riverbankcomputing.co.uk/software/sip/download
and unzip to any location.
• Make sure python is in PATH of environment variables -> PATH = %PATH
%;C:\python26
• Go to cmd promt -> go to the SIP location (location of download) ->
run :/python configure.py
• It will take all the default setting for configuration, the default
directories will be in c:\python26 (change if required)
• Go to Start -> programs -> MS visual studios -> visuals studio tools-
> command prompt. Go to SIP folder (location of download)
• \> nmake -> this will run makefile and build sip.exe and sip.pyd
• \> nmake install -> this will copy: sip.exe, sip.pyd,sip.h,
sipconfig.py, sipdistutils.py in C:\python26
• Go to the folder where the manually written .sip file is present in
command prompt and run the following:
sip -e -j 1 -c . xyz.sip
Steps to create an extension module:
1. Create a “.sip” specification file for the C/C++ library
a. Follow the syntax definitions as given in
http://www.riverbankcomputing.co.uk/static/Docs/sip4/specification_files.html#syntax-definition
b. Appropriately add the C/C++ classes, functions, methods and
structures in the specification file.
2. Run the SIP tool utility on the specification file to create the
intermediate C/C++ code.
3. Copy and edit the simple build script as shown in
http://www.riverbankcomputing.co.uk/static/Docs/sip4/using.html#a-simple-c-example
4. Run the build script to create the makefile, the CModule, the .sbf
files
5. Run Visual Studios nmake utility on the makefile to create the .pyd
file which is the final module which can be imported from python.
--
http://mail.python.org/mailman/listinfo/python-list
pyconfig.h
Hi All, I am working on porting python on vxworks and hence was updating the PC \pyconfig.h file for configurng python. As I am reading the file and updating manually I come across lot many preprocessor directives which I dont understand e.g. HAVE_NICE etc. May be this is standard nomenclature and I am not aware of it. My point and qwery is that how can I get info about all these directives. I am perplexed to enable or disable any of them with half knowledge. regards, -- http://mail.python.org/mailman/listinfo/python-list
