python-2.5

How to convert tomorrows (at specific time) date to a timestamp

青春壹個敷衍的年華 提交于 2019-11-29 08:24:43
How can i actually create a timestamp for the next 6 o'clock, whether that's today or tomorrow? I tried something with datetime.datetime.today() and replace the day with +1 and hour = 6 but i couldnt convert it into a timestamp. Need your help To generate a timestamp for tomorrow at 6 AM, you can use something like the following. This creates a datetime object representing the current time, checks to see if the current hour is < 6 o'clock or not, creates a datetime object for the next 6 o'clock (including adding incrementing the day if necessary), and finally converts the datetime object into

How to install Python ssl module on Windows?

穿精又带淫゛_ 提交于 2019-11-28 17:05:13
The Google App Engine Launcher tells me: WARNING appengine_rpc.py:399 ssl module not found. Without the ssl module, the identity of the remote host cannot be verified, and connections may NOT be secure. To fix this, please install the ssl module from http://pypi.python.org/pypi/ssl . I downloaded the package and it contained a setup.py file. I ran: python setup.py install and then: Python was built with Visual Studio 2003; blablabla use MinGW32 Then I installed MinGW32 and now the compilation doesn't work. The end of the compilation errors contains: ssl/_ssl2.c:1561: error: `CRYPTO_LOCK'

What does from __future__ import absolute_import actually do?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 15:05:34
I have answered a question regarding absolute imports in Python, which I thought I understood based on reading the Python 2.5 changelog and accompanying PEP . However, upon installing Python 2.5 and attempting to craft an example of properly using from __future__ import absolute_import , I realize things are not so clear. Straight from the changelog linked above, this statement accurately summarized my understanding of the absolute import change: Let's say you have a package directory like this: pkg/ pkg/__init__.py pkg/main.py pkg/string.py This defines a package named pkg containing the pkg

How to properly use python's isinstance() to check if a variable is a number?

别来无恙 提交于 2019-11-28 05:42:04
I found some old Python code that was doing something like: if type(var) is type(1): ... As expected, pep8 complains about this recommending usage of isinstance() . Now, the problem is that the numbers module was added in Python 2.6 and I need to write code that works with Python 2.5+ So if isinstance(var, Numbers.number) is not a solution. Which would be the proper solution in this case? In Python 2, you can use the types module : >>> import types >>> var = 1 >>> NumberTypes = (types.IntType, types.LongType, types.FloatType, types.ComplexType) >>> isinstance(var, NumberTypes) True Note the

Test a string if it's Unicode, which UTF standard is and get its length in bytes?

孤人 提交于 2019-11-28 05:29:27
I need to test if a string is Unicode, and then if it whether it's UTF-8. After that, get the string's length in bytes including the BOM , if it ever uses that. How can this be done in Python? Also for didactic purposes, what does a byte list representation of a UTF-8 string look like? I am curious how a UTF-8 string is represented in Python. Latter edit: pprint does that pretty well. try: string.decode('utf-8') print "string is UTF-8, length %d bytes" % len(string) except UnicodeError: print "string is not UTF-8" In Python 2, str is a sequence of bytes and unicode is a sequence of characters.

How to convert tomorrows (at specific time) date to a timestamp

陌路散爱 提交于 2019-11-28 01:53:18
问题 How can i actually create a timestamp for the next 6 o'clock, whether that's today or tomorrow? I tried something with datetime.datetime.today() and replace the day with +1 and hour = 6 but i couldnt convert it into a timestamp. Need your help 回答1: To generate a timestamp for tomorrow at 6 AM, you can use something like the following. This creates a datetime object representing the current time, checks to see if the current hour is < 6 o'clock or not, creates a datetime object for the next 6

Chinese and Japanese character support in python

女生的网名这么多〃 提交于 2019-11-27 22:30:38
How to read correctly japanese and chinese characters. I'm using python 2.5. Output is displayed as "E:\Test\?????????" path = r"E:\Test\は最高のプログラマ" t = path.encode() print t u = path.decode() print u t = path.encode("utf-8") print t t = path.decode("utf-8") print t Martijn Pieters Please do read the Python Unicode HOWTO ; it explains how to process and include non-ASCII text in your Python code. If you want to include Japanese text literals in your code, you have several options: Use unicode literals (create unicode objects instead of byte strings), but any non-ascii codepoint is represented

How do I zip the contents of a folder using python (version 2.5)?

☆樱花仙子☆ 提交于 2019-11-27 11:14:52
Once I have all the files I require in a particular folder, I would like my python script to zip the folder contents. Is this possible? And how could I go about doing it? Adapted version of the script is: #!/usr/bin/env python from __future__ import with_statement from contextlib import closing from zipfile import ZipFile, ZIP_DEFLATED import os def zipdir(basedir, archivename): assert os.path.isdir(basedir) with closing(ZipFile(archivename, "w", ZIP_DEFLATED)) as z: for root, dirs, files in os.walk(basedir): #NOTE: ignore empty directories for fn in files: absfn = os.path.join(root, fn) zfn =

Read data from csv-file and transform to correct data-type

我只是一个虾纸丫 提交于 2019-11-27 08:39:23
I've got following problem. I wrote a 2-dimensional list, where each column is of a different type (bool, str, int, list), to a csv-file. Now I want to read out the data from the csv-file again. But every cell I read is interpreted as a string. How can I automatically convert the read-in data into the correct type? Or better: Is there a possibility, to tell the csv-reader the correct data-type of each column? Sample Data (like in csv-file): IsActive,Type,Price,States True,Cellphone,34,"[1, 2]" ,FlatTv,3.5,[2] False,Screen,100.23,"[5, 1]" True,Notebook, 50,[1] As the docs explain , the CSV

Sort nested dictionary by value, and remainder by another value, in Python

杀马特。学长 韩版系。学妹 提交于 2019-11-27 04:03:45
Consider this dictionary format. {'KEY1':{'name':'google','date':20100701,'downloads':0}, 'KEY2':{'name':'chrome','date':20071010,'downloads':0}, 'KEY3':{'name':'python','date':20100710,'downloads':100}} I'd like the dictionary sorted by downloads first, and then all items with no downloads sorted by date. Obviously a dictionary cannot be sorted, I just need a sorted listed of keys I can iterate over. ['KEY3','KEY1','KEY2'] I can already sort the list by either value using sorted , but how do I sort by second value too? Use the key argument for sorted() . It lets you specify a function that,