python-2.6

Can't install Pillow on centos

Can't install Pillow on centos Question: I have cenots 6.3 and python 2.6 on it when I try to install it via easyinstall I get following error: _imaging.c:76:20: error: Python.h: No such file or directory In file included from /tmp/easy_install-HY7WI1/Pillow-2.3.0/libImaging/Imaging.h:14, from _imaging.c:82: /tmp/easy_install-HY7WI1/Pillow-2.3.0/libImaging/ImPlatform.h:14:2: error: #error Sorry, this library requires support for ANSI prototypes. /tmp/easy_install-HY7WI1/Pillow-2.3.0/libImaging/ImPlatform.h:17:2: error: …

Total answers: 3

global variable warning in python

global variable warning in python Question: I have a python 2.6 script (yes I know I should upgrade to at least 2.7) that looks like this: ret_code = 0 def some_func() global ret_code … if __name__ == ‘__main__’: global ret_code … Now I get a warning if I run the code: *SyntaxWarning: name ‘ret_code’ is …

Total answers: 1

pyodbc insert into sql

pyodbc insert into sql Question: I use a MS SQL express db. I can connect and fetch data. But inserting data does not work: cursor.execute(“insert into [mydb].[dbo].[ConvertToolLog] ([Message]) values(‘test’)”) I get no error but nothing is inserted into the table. Directly after I fetch the data the inserted row is fetched. But nothing is saved. …

Total answers: 2

Most pythonic way to convert a string to a octal number

Most pythonic way to convert a string to a octal number Question: I am looking to change permissions on a file with the file mask stored in a configuration file. Since os.chmod() requires an octal number, I need to convert a string to an octal number. For example: ‘000’ ==> 0000 (or 0o000 for you …

Total answers: 2

Difference between python – getmtime() and getctime() in unix system

Difference between python – getmtime() and getctime() in unix system Question: Can someone please specify what is the difference between os.path.getmtime(path) and os.path.getctime(path) in unix systems . As per the defnition in python docs: os.path.getmtime(path) Return the time of last modification of path. The return value is a number giving the number of seconds since …

Total answers: 3

Python readlines() usage and efficient practice for reading

Python readlines() usage and efficient practice for reading Question: I have a problem to parse 1000’s of text files(around 3000 lines in each file of ~400KB size ) in a folder. I did read them using readlines, for filename in os.listdir (input_dir) : if filename.endswith(“.gz”): f = gzip.open(file, ‘rb’) else: f = open(file, ‘rb’) file_content …

Total answers: 2

Why does Python have a format function as well as a format method

Why does Python have a format function as well as a format method Question: The format function in builtins seems to be like a subset of the str.format method used specifically for the case of a formatting a single object. eg. >>> format(13, ‘x’) ‘d’ is apparently preferred over >>> ‘{0:x}’.format(13) ‘d’ and IMO it …

Total answers: 2

Determine season given timestamp in Python using datetime

Determine season given timestamp in Python using datetime Question: I’d like to extract only the month and day from a timestamp using the datetime module (not time) and then determine if it falls within a given season (fall, summer, winter, spring) based on the fixed dates of the solstices and equinoxes. For instance, if the …

Total answers: 12

Extract time from datetime and determine if time (not date) falls within range?

Extract time from datetime and determine if time (not date) falls within range? Question: The problem is that I want it to ignore the date and only factor in the time. Here is what I have: import time from time import mktime from datetime import datetime def getTimeCat(Datetime): # extract time categories str_time = datetime.strptime(Datetime, …

Total answers: 2

Visibility of global variables in imported modules

Visibility of global variables in imported modules Question: I’ve run into a bit of a wall importing modules in a Python script. I’ll do my best to describe the error, why I run into it, and why I’m tying this particular approach to solve my problem (which I will describe in a second): Let’s suppose …

Total answers: 9