python-3.3

python os.listdir doesn't show all files

吃可爱长大的小学妹 提交于 2019-12-07 06:10:37
问题 In my windows7 64bit system, there is a file named msconfig.exe in folder c:/windows/system32 . Yes, it must exists. But when i use os.listdir to search the folder c:/windows/system3 2, I didn't get the file. Here is the test code, in t1.py : import os files = os.listdir("c:/windows/system32") for f in files: if f.lower() == "msconfig.exe": print(f) After run python t1.py , I get nothing. Why the file missed? How can I list all files under a folder? BTW: I am using python 3.3.0 32bit version

Using pySerial with Python 3.3

て烟熏妆下的殇ゞ 提交于 2019-12-06 23:43:02
问题 I've seen many code samples using the serial port and people say they are working codes too. The thing is, when I try the code it doesn't work. import serial ser = serial.Serial( port=0, baudrate=9600 # parity=serial.PARITY_ODD, # stopbits=serial.STOPBITS_TWO, # bytesize=serial.SEVENBITS ) ser.open() ser.isOpen() print(ser.write(0xAA)) The error it gives me is : "SerialException: Port is already opened". Is it me using python3.3 the problem or is there something additional I need to instal ?

How to convert days into months using datetime in Python3?

吃可爱长大的小学妹 提交于 2019-12-06 14:36:31
Is there a special method to derive this or do we have to create loops? The parameters for this function is actually (year, num_of_days). But I have no idea how to derive months from this. This is what I have so far (incomplete) but it doesn't take into the different month days into account. Is there an easier way to tackle this question? Thanks in advance! def daynum_to_date(year : int, daynum : int) -> datetime.date: '''Return the date corresponding to the year and the day number, daynum, within the year. Hint: datetime handles leap years for you, so don't think about them. Examples: >>>

Python3.3 rounding up

最后都变了- 提交于 2019-12-06 13:35:25
In Python I would like to divide two numbers and if the answer is not an integer I want the number to be rounded up to the number above. For example 100/30 not to give 33.3 but to give 4. Can anyone suggest how to do this? Thanks. you can use the ceil function in math library that python has, but also you can take a look why in a logical sense a = int(100/3) # this will round down to 3 b = 100/3 # b = 33.333333333333336, a and b are not equal so we can generalize into the following def ceil(a, b): if (b == 0): raise Exception("Division By Zero Error!!") # throw an division by zero error if int

Is hash() randomization considered cryptographically strong?

最后都变了- 提交于 2019-12-06 12:08:18
问题 Starting from the CPython 3.3, hash randomization is enabled by default. On previous versions it could be turned on by specifying the -R command-line option or by setting the PYTHONHASHSEED environment variable to random . Citing the documentation: By default, the __hash__() values of str, bytes and datetime objects are “salted” with an unpredictable random value. Although they remain constant within an individual Python process, they are not predictable between repeated invocations of Python

How to download a file in parts

只愿长相守 提交于 2019-12-06 11:50:25
I'm writing a program that downloads files anywhere up to a 1Gb in size. Right now I'm using the requests package to download files, and although it works (I think it times out sometimes) it is very slow. I've seen some examples multi-part download examples using urllib2 but I'm looking for a way to use urllib3 or requests, if that package has the ability. How closely have you looked at requests' documentation ? In the Quickstart documentation the following is described r = requests.get(url, stream=True) r.raw.read(amount) The better way, however, to do this is: fd = open(filename, 'wb') r =

Compare directories on file/folder names only, printing any differences?

泄露秘密 提交于 2019-12-06 10:23:46
How do I recursively compare two directories (comparison should be based only on file name) and print out files/folders only in one or the other directory? I'm using Python 3.3. I've seen the filecmp module, however, it doesn't seem to quite do what I need. Most importantly, it compares files based on more than just the filename. Here's what I've got so far: import filecmp dcmp = filecmp.dircmp('./dir1', './dir2') dcmp.report_full_closure() dir1 looks like this: dir1 - atextfile.txt - anotherfile.xml - afolder - testscript.py - anotherfolder - file.txt - athirdfolder And dir2 looks like this:

winpdb not working with python 3.3

一个人想着一个人 提交于 2019-12-06 05:04:52
问题 I can't get rpdb2 to run with python 3.3, while that should be possible according to several sources. $ rpdb2 -d myscript.py A password should be set to secure debugger client-server communication. Please type a password:x Password has been set. Traceback (most recent call last): File "/usr/local/bin/rpdb2", line 31, in <module> rpdb2.main() File "/usr/local/lib/python3.3/dist-packages/rpdb2.py", line 14470, in main StartServer(_rpdb2_args, fchdir, _rpdb2_pwd, fAllowUnencrypted, fAllowRemote,

Bash alias --> Python 2.7 to Python 3.3

江枫思渺然 提交于 2019-12-06 05:01:25
问题 I am trying to make Python 3.4.2 the default in Linux (currently it is 2.7.6). I am not very knowledgeable on this stuff, but I have read in several places online that you can simply put an alias in the ~/.bashrc or ~/.bash_aliases file like this: alias python='python3' I don't have either the ~/.bashrc or ~/.bash_aliases file . . . I am assuming you can just create them. I have done that, but the alias doesn't seem to be working. Am I missing something? Do you need the shebang at the

_socket module import error on fresh python 3.3.5 install

亡梦爱人 提交于 2019-12-06 04:49:19
I installed python 3.35 and I'm getting this error: Traceback (most recent call last): File "C:/Users/Augusto/PycharmProjects/Plot/Database.py", line 48, in <module> import socket File "C:\Python33\lib\socket.py", line 47, in <module> import _socket ImportError: DLL load failed: The specified module could not be found I'm running it on Windows 7 64 bits. I tried both Python installations (Windows x86-64 MSI installer and Windows x86 MSI installer) but both present the same error. I removed the python 2.7 installation from the path in the chance it was causing the error, but no luck. EDIT: os