top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Illegal seek error with seek() and os.lseek() in python

0 votes
739 views

I am trying to use os.open() and os.lseek() methods to operate on a device file in Linux. My code goes something like this -

# first, open the file as a plain binary
try:
self.file = open(/dev/relpcfpga, "r+b", buffering=0)

except IOError:
raise IOError ('Failed to open.')

# Figure out file size
self.file.seek(0, 2)
self.file_size = self.file.tell()

The method seek() complains "OSError: [Errno 29] Illegal seek"
The device relpcfpga is a char device.

The same code works with a normal text file.
I have tried to use os.open() and os.lseek() methods, but see the same error.
Is there a different method to operate on device files?

posted May 14, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Some file streams are not seekable. Specifically, some (all?) char
devices aren't seekable (because e.g. they can't be rewound or they have
no end). You'd get the same error in C (well it would return -1).

See also: http://www.linuxintro.org/wiki/Device

answer May 14, 2013 by anonymous
Similar Questions
0 votes

I am trying to write a program that requires me hitting a https web link. However, I can't seem to get it to work. The program works fine when dealing with http sites, however, when I try it with a https site I get

socket.gaierror: [Errno 11001] getaddrinfo failed

It seems like it has something to do with the ssl not working, however, I do have the ssl.py in the python library and I have no problem importing it.

My code is below. Any help would be greatly appreciated.

import urllib.request
auth = urllib.request.HTTPSHandler()
proxy = urllib.request.ProxyHandler({'http':'my proxy'})
opener = urllib.request.build_opener(proxy, auth)
f = opener.open('http://www.google.ca/')
+1 vote

I want to write my own Screenshot Taking program in Python for Mac OS X.

Example : Whenever Command + Shift + 3 is pressed ==> whatever is there on the screen, should be grabbed / captured, and should be stored on my local with my own desired path, and name should automatically given as SnapshotX.. as in Snapshot1, Snapshot2, etc...

The same goes with Command + Shift + 4 ==> the only difference is that, it allows you to select a particular area to be captured / grabbed.

Command + Shift + 5 ==> This one is a little bit tricky which I am looking for. This shortcut doesn't exist. I want to create one of my own, where it would grab the entire webpage's screenshot which I am currently working on, and store the name as the webpage's link.

0 votes

I need to run xmlrpc Server under Python 3.3 and Client under Python 2.7. But when I try to do so, I receive the following exception:

":global name 'xmlrpclib' is not defined"

What is the reason for such an exception. As far as I understand xmlrpc is language independent.

+2 votes

I am working on drawing map from shape file in Python 3.2 basemap. But, the longitude values at the bottom axis are only shown partially. Also, all latitude values are missing.

Here is my python code.

import shapefile as sf
import sys
import numpy as np
import matplotlib.pylab as plt
from mpl_toolkits.basemap import Basemap

 map = Basemap(projection='stere', lon_0=-106.4, lat_0= 31.9, lat_ts = 31.9, 
 llcrnrlat=31.7, urcrnrlat= 31.85, 
 llcrnrlon=-106.5 , urcrnrlon= -106.1, 
 rsphere=6371200., resolution='l', area_thresh=1000)

 plt.figure(num=None, figsize=(10, 8), dpi=80, facecolor='w', edgecolor='k')

parallels = np.arange(31.7, 31.85, 0.25)

map.drawparallels(parallels, labels=[0, 0, 0, 1] , fontsize=10, labelstyle='+/-', dashes=[2, 2])

meridians = np.arange (-106.5, -106.1, 0.25)

map.drawmeridians(meridians, labels=[0, 0, 0, 1], fontsize=10, labelstyle='+/-' , dashes=[2, 2])

No matter how I changed the labels, the latitude/longitude legend values are still missing.

...