Posts Tagged ‘Python’

Good resources for learning Factor

Monday, August 23rd, 2010

Having recently come across this introduction to Factor, I’ve been a bit curious to learn more. Aside from the official FAQ mentioned there, do you have resources for learning the language (as well as the stack-based “paradigm,” if that’s the right word) that you’ve found helpful?

As a side note, would learning Forth help, or is that like comparing C to Python (or what have you)?

Quickly find differences between two large text files

Monday, August 23rd, 2010

I have two 3GB text files, each file has around 80 million lines. And they share 99.9% identical lines (file A has 60,000 unique lines, file B has 80,000 unique lines).

How can I quickly find those unique lines in two files? Is there any ready-to-use command line tools for this? I’m using Python but I guess it’s less possible to find a efficient Pythonic method to load the files and compare.

Any suggestions are appreciated.

Customizing project and app templates in django

Monday, August 23rd, 2010

I would like to customize the files and folders created when running

python manage.py startapp appname

I find doing some things over and over again and I think it would be neat, if my customizations are present when I create a new app.

Do you know where I can customize the default files when an app is created?

Email body is a string sometimes and a list sometimes. Why?

Sunday, August 22nd, 2010

My application is written in python. What I am doing is I am running a script on each email received by postfix and do something with the email content. Procmail is responsible for running the script taking the email as input. The problem started when I was converting the input message(may be text) to email_message object(because the latter comes in handy). I am using email.message_from_string (where email is the default email module, comes with python).


import email
message = email.message_from_string(original_mail_content)
message_body = message.get_payload()

This message_body is sometimes returning a list[email.message.Message instance,email.message.Message instance] and sometime returning a string(actual body content of the incoming email). Why is it. And even I found one more observation. When I was browsing through the email.message.Message.get_payload() docstring, I found this..
“”"
The payload will either be a list object or a string.If you mutate
the list object, you modify the message’s payload in place…..”"”

So how do I have generic method to get the body of email through python? Please help me out.

How to restart the command window in Python?

Sunday, August 22nd, 2010

I am looking for something similar to ‘clear’ in Matlab: A command/function which removes all variables from the workspace, releasing them from system memory. Is there such a thing in Python?

Python Sockets

Sunday, August 22nd, 2010
Hello there,

I’m currently working on a very simple script. It opens a socket and tries to read the incoming data. Currently I’m using the recv method which puts the entire incoming data in a single string variable. This is all fine but the package I’m receiving contains various data which I need to parse out.

The pattern in the package is rather straightforward, the first incoming integer tells me how long the incoming string is and after that a second integer telling me how long the second string is and so it goes. Here is my problem, how do I fetch the first integer from a string? Not thinking this was possible at all I started to look at buffers (from the Java ByteArrayBuffer) but I didn’t find what I was looking for. There was one method recv_into which takes a read-write buffer but I didn’t quite get that.

So, basically what I want to do is open a socket and read an integer or a string from that socket much similar to Java. Is this possible? I cannot be the first one trying out socket communication in Python! :)

Kind regards,
Niklas

Accessing later index in array using enumerate(array) Python

Sunday, August 22nd, 2010

hey guys, how would you access an array from array[n] in an array of 100 floats in this for loop (i need the enumerate):

for index,value in enumerate(array):
    #do stuff with array[n]
    n=n+1

im trying to make it so that it operates in a smaller and smaller space each iteration..

thanks

Why do game companies look for only C/C++?

Sunday, August 22nd, 2010

Most of the requirements for a game programming job I’ve looked at required good C/C++ skills. I agree, most game engines are written in C/C++. But aren’t the engines USED in a scripting languages? Don’t the companies need scripting programmers to actually code the game from the game engine?

Why haven’t I ever seen a company that requires good Python skills? Or do most companies just make their own engines?

VIM 256 colors mode, laggy php files

Sunday, August 22nd, 2010

Hi, I’m using 256-colors theme in vim (set t_Co=256) and all php files opens about 8 seconds.

  • It’s my local dual-core machine
  • It doesn’t depend on color scheme I used (zenburn, wombat, wombat256)
  • HTML, Python, JS or every else files opens momentary
  • It takes about 8 sec even to create new php files (:o newfile.php)
  • I’ve setting up my terminal correctly
  • Everything fine if I’m using 16 colors (set t_Co=16)

I really want to use 256-colors mode, it looks much prettier, but I can’t get rid of this lags.

create entity – google app engine – most convenient way?

Sunday, August 22nd, 2010

whats the most simple way to create a new entity in google app engine? i used now a simple servlet form, but it is annoying to upload a project only because you want to create a new entity. i am using eclipse with java. ( creating entities is documented on google only for python )