| | |
Read from /dev/zero
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2007
Posts: 148
Reputation:
Solved Threads: 32
I'm curious why this bit of code doesn't work. When run it returns a blank line. Note: this is making use of a linux device file so it should not be expected to run properly on Windows.
I'm pretty new to Python so I might be way off base. I appreciate any suggestions.
python Syntax (Toggle Plain Text)
#!/usr/bin/env python import os infile = os.open("/dev/zero", os.O_RDONLY) charout = os.read(infile,1) os.close(infile) print charout
I'm pretty new to Python so I might be way off base. I appreciate any suggestions.
Last edited by mn_kthompson; Nov 12th, 2007 at 5:21 pm.
•
•
Join Date: Nov 2007
Posts: 148
Reputation:
Solved Threads: 32
OK, I have been able to verify that something is being read from my device file, but nothing is printable. I have modified the code to read as follows
And here is the output:
So you can see that the charout file is getting 51 bytes of data, but it still wont print anything but a blank line. Does this give anyone any clues as to why I'm not getting a bunch of zeros on my screen?
python Syntax (Toggle Plain Text)
#!/usr/bin/env python import os charout = "XXX" print len(charout) infile = os.open("/dev/zero", os.O_RDONLY) charout = os.read(infile,51) os.close(infile) print charout print len(charout)
And here is the output:
kevin@MSU1375020:~$ python read.py 3 51
So you can see that the charout file is getting 51 bytes of data, but it still wont print anything but a blank line. Does this give anyone any clues as to why I'm not getting a bunch of zeros on my screen?
•
•
Join Date: Dec 2006
Posts: 1,054
Reputation:
Solved Threads: 297
They are not printable characters (probably) and so who knows where they come from. To test this, try printing the decimal value of each character. It might just be a bunch of decimal zeroes (which is zero, the printable zero is decimal 48), or EOFs, or garbage created by some sort of "noise".
Python Syntax (Toggle Plain Text)
for each_char in charout: print ord(each_char),
![]() |
Similar Threads
- Do I need a new webhost? (IT Professionals' Lounge)
- Data retrieving using ms-access (VB.NET)
- read from database and writing the contents into a text file (C)
- how to read input from barcode scanner? (PHP)
- Cannot Get Dev-C++ to compile correctly (C++)
- How to use Dev C++ (C++)
- What is bloodshed dev cpp (C++)
- Dev bloodshed question. ������ (C++)
Other Threads in the Python Forum
- Previous Thread: Trying to compare the contents of two text files and save the difference
- Next Thread: Needing help with wxPython MediaCtrl
| Thread Tools | Search this Thread |
Tag cloud for Python
abrupt ansi anti approximation assignment avogadro backend basic beginner binary bluetooth calculator character code customdialog decimals dictionaries dictionary drive dynamic examples excel exe file float format ftp function gnu graphics gui heads homework http ideas import input java launcher leftmouse line linux list lists loop module mouse number numbers output parsing path pointer port prime program programming progressbar projects py2exe pygame pyqt python random recursion recursive refresh schedule scrolledtext sqlite ssh statistics stdout string strings sudokusolver sum table terminal text thread threading time tkinter tlapse tricks tuple tutorial twoup ubuntu unicode update urllib urllib2 variable wikipedia windows write wxpython xlib






