473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

script fichiers binaires lecture écriture

Je connais mal python et n'est pas trop le temps de m'y plonger bien
que cela semble être assez puissant...

import sys
import ixio
import os

M = ixio.getMAC("eth0")
S = "%08X %08X" % (M[0] | M[1]<<8 | M[2]<<16 | M[3]<<24, M[4] |
M[5]<<8)
K = "Errorin:"
if len(sys.argv) <> 3:
print "Usage %s <src-file> <dst-file>" % sys.argv[0]
else:
I = open(sys.argv[1],"rb")#ouverture de tpsd.pre avec le flag rb
pour read in binary mode
O = open(sys.argv[2],"wb")
while 1:
blk = I.read(1<<13)
try:
i = blk.index(K)
blk = "%sErrorin:%s%s" \
% (blk[:i],S,blk[i+len(K)+len(S):])
O.write(blk)
except ValueError:
O.write(blk)
if len(blk)<1<<13:
break
O.close()
I.close()

Voici l'erreur que j'obtiens en essayant d'exécuter ce script:

AttributeError: 'string' object has no attribute 'index'

D'après moi, index est une méthode de la classe string et non un
attribut...Je ne comprend donc pas... Enfin, je précise que je suis
malheureusement en version 1.5 de python... :(

Autre question: 1<<13 est censé être une taille en octet: comment
cela se lit-t-il?

Merci d'avance de m'aclairer sur cette erreur et cette question.

Jul 19 '05 #1
4 2117
In English:

I don't know much about python and I won't have much time to learn much
about it even if it seems powerful...

import sys
import ixio
import os

M = ixio.getMAC("eth0")
S = "%08X %08X" % (M[0] | M[1]<<8 | M[2]<<16 | M[3]<<24, M[4] |
M[5]<<8)
K = "Errorin:"
if len(sys.argv) <> 3:
print "Usage %s <src-file> <dst-file>" % sys.argv[0]
else:
I = open(sys.argv[1],"rb")#ouverture de tpsd.pre avec le flag rb
pour read in binary mode
O = open(sys.argv[2],"wb")
while 1:
blk = I.read(1<<13)
try:
i = blk.index(K)
blk = "%sErrorin:%s%s" \
% (blk[:i],S,blk[i+len(K)+len(S):])
O.write(blk)
except ValueError:
O.write(blk)
if len(blk)<1<<13:
break
O.close()
I.close()

Here is an error I get trying to run this script:

AttributeError: 'string' object has no attribute 'index'

According to me, index() is a method of the string class but not an
attribute. So I don't understand the error message. Be aware that I'm
using pyhton 1.5, unfortunately...

Another question: "1<<13" is supposed to be a size in bytes but can you
explain to me how to read this?

Thanks for helping me understanding the error message and size thing!!

Jul 19 '05 #2
Statesman wrote:
In English:

I don't know much about python and I won't have much time to learn much
about it even if it seems powerful...
(snip code)
Here is an error I get trying to run this script:

AttributeError: 'string' object has no attribute 'index'

According to me, index() is a method of the string class but not an
attribute. So I don't understand the error message.
In Python, functions are first class citizens (a function is an object
you can bind to a variable, pass as an argument, return from another
function etc...), so methods *are* actually attributes...
Be aware that I'm
using pyhton 1.5, Err... latest is 2.4.1, and the language has really, really changed. You
should consider upgrading...
unfortunately...


BTW, in 1.5.x, you can use the String module instead of string class
methods:

import String
s = "allo"
String.index(s, "a")

but really, consider upgrading to a newer version...

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Jul 19 '05 #3
Statesman wrote in comp.lang.python:

<en>
Hi Statesman
comp.lang.python is the english-speaking Python forum. You may want to
try the french-speaking one at fr.comp.lang.python (xpost and fu2 set)
</en>
Je connais mal python et n'est pas trop le temps de m'y plonger bien
que cela semble être assez puissant...

import sys
import ixio
import os

M = ixio.getMAC("eth0")
S = "%08X %08X" % (M[0] | M[1]<<8 | M[2]<<16 | M[3]<<24, M[4] |
M[5]<<8)
K = "Errorin:"
if len(sys.argv) <> 3:
print "Usage %s <src-file> <dst-file>" % sys.argv[0]
else:
I = open(sys.argv[1],"rb")#ouverture de tpsd.pre avec le flag rb
pour read in binary mode
O = open(sys.argv[2],"wb")
while 1:
blk = I.read(1<<13)
try:
i = blk.index(K)
blk = "%sErrorin:%s%s" \
% (blk[:i],S,blk[i+len(K)+len(S):])
O.write(blk)
except ValueError:
O.write(blk)
if len(blk)<1<<13:
break
O.close()
I.close()

Voici l'erreur que j'obtiens en essayant d'exécuter ce script:

AttributeError: 'string' object has no attribute 'index'

D'après moi, index est une méthode de la classe string et non un
attribut...Je ne comprend donc pas...
En Python, les fonctions sont des objets comme les autres. Donc les
methodes sont effectivement des attributs... (bon, dans le détail c'est
un poil plus compliqué que ça, mais là je te laisse consulter la doc...
si tu tiens vraiment à comprendre tous les détails d'implémentation)
Enfin, je précise que je suis
malheureusement en version 1.5 de python... :(
Euh... la dernière est la 2.4.1, il serait peut-être temps d'envisager
une mise à jour.

En attendant, dans la 1.5.x, tu peux utiliser le module String:
import String
s = "allo"
String.index(s, "a")

(de mémoire, pas testé).

Autre question: 1<<13 est censé être une taille en octet: comment
cela se lit-t-il?
opérateur de décalage de bits... 1 << 13 == 8192
Merci d'avance de m'aclairer sur cette erreur et cette question.


HTH
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Jul 19 '05 #4
bruno modulix <on***@xiludom.gro> writes:
Be aware that I'm
using pyhton 1.5,

Err... latest is 2.4.1, and the language has really, really changed. You
should consider upgrading...
unfortunately...


BTW, in 1.5.x, you can use the String module instead of string class
methods:


In python 1.5.x, string objects didn't have methods. That's why he's
getting the error. He has to use the string module instead.

I agree with bruno - you *really* should upgrade.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: mandr | last post by:
Bonjour , j'ai un petit pb sur mon script suivant : <?php // Ouverture de la session session_start();
4
by: Amir Michail | last post by:
Hi, We are planning to have "lecture preparation" discussions in comp3141 at UNSW, where anyone can participate -- not only students taking the subject. There is a heavy python component in...
4
by: Granite Stone | last post by:
I am posting this at this newsgroup protesting a soon to be lecture at the United Church of Canada, Toronto. Please read the article and write to the University of Canada and www.tsmr.org It has...
0
by: isore | last post by:
Convertion php to asp.net : PB lecture fichier .ini URGENT URGENT URGENT URGENT URGENT URGENT J'ai un code en php (http://parisports.free.fr) mais le client veut le même en asp.net J'ai...
19
by: thisis | last post by:
Hi All, i have this.asp page: <script type="text/vbscript"> Function myFunc(val1ok, val2ok) ' do something ok myFunc = " return something ok" End Function </script>
2
by: tolgafiratoglu | last post by:
Hope you like it: http://www.netskeleton.com good for beginners to framework concept.
1
by: Aaron Watters | last post by:
Hi folks. Andy Pausch who headed up the Alice project which aims to teach 3D animation using Python has gained additional fame from his "last lecture" where he talks about being diagnosed with...
2
by: Gilbert Tordeur | last post by:
Bonjour. Mon application Web génère plusieurs fichiers pdf, que l'utilisateur doit télécharger sur son poste local. Pour provoquer le téléchargement du premier fichier, je fais : Dim...
10
by: Michel Leunen | last post by:
Hi, I'm trying to write a python script for Nautilus. To get the list of files selected in the Nautilus right pane, you use the $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS environment variable which is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.