UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 308: character maps to undefined
For 'mimetypes' in the code given below, python is giving the following error. Kindly help. import os matches = [] for (dirname, dirshere, fileshere) in os.walk(r'C:\Python34'): for filename in fileshere: if filename.endswith('.py'): pathname = os.path.join(dirname, filename) if 'mimetypes' in open(pathname).read(): matches.append(pathname) Traceback (most recent call last): File pyshell#165, line 5, in module if 'mimetypes' in open(pathname).read(): File C:\Python34\lib\encodings\cp1252.py, line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 308: character maps to undefined -- https://mail.python.org/mailman/listinfo/python-list
How to recover bytes function?
file = open('data.bin', 'rb') bytes = file.read() bytes b'\x00\x00\x00\x02spam\x00\x03?\x9d\xf3\xb6' records = [bytes([char] * 8) for char in b'spam'] TypeError: 'bytes' object is not callable How to recover bytes function? -- https://mail.python.org/mailman/listinfo/python-list
io.UnsupportedOperation: fileno
import sys for stream in (sys.stdin, sys.stdout, sys.stderr): print(stream.fileno()) io.UnsupportedOperation: fileno -- https://mail.python.org/mailman/listinfo/python-list
Re: io.UnsupportedOperation: fileno
What is the problem and how to overcome this problem? -- https://mail.python.org/mailman/listinfo/python-list
Re: io.UnsupportedOperation: fileno
fileno() in not supported. Is it only in 3.1? What is the workaround? -- https://mail.python.org/mailman/listinfo/python-list
Bad file descriptor
import os os.write(1, b'Hello descriptor world\n') OSError: Bad file descriptor How to give a file descriptor number to this function? How to get a file descriptor number? -- https://mail.python.org/mailman/listinfo/python-list
fileno() not supported in Python 3.1
import sys for stream in (sys.stdin, sys.stdout, sys.stderr): print(stream.fileno()) io.UnsupportedOperation: fileno Is there a workaround? -- https://mail.python.org/mailman/listinfo/python-list
Re: fileno() not supported in Python 3.1
How to get file descriptor number for the following: sys.stdin sys.stdout sys.stderr It is displaying io.UnsupportedOperation: fileno error Kindly help. -- https://mail.python.org/mailman/listinfo/python-list
How to get file descriptors of sys.stdin, sys.stdout and sys.stderr?
How to get file descriptors of sys.stdin, sys.stdout and sys.stderr? -- https://mail.python.org/mailman/listinfo/python-list
How to get file descriptors of sys.stdin, sys.stdout and sys.stderr?
How to get file descriptors of sys.stdin, sys.stdout and sys.stderr? -- https://mail.python.org/mailman/listinfo/python-list
What is \1 here?
What does \1 do in the following piece of code(fourth line)? import re print(re.sub('[ABC]', '*', 'XAXAXBXBXCXC')) print(re.sub('[ABC]_', '*', 'XA-XA_XB-XB_XC-XC_')) print(re.sub('(.) spam', 'spam\\1', 'x spam, y spam')) def mapper(matchobj): return 'spam' + matchobj.group(1) print(re.sub('(.) spam', mapper, 'x spam, y spam')) -- https://mail.python.org/mailman/listinfo/python-list
What is ?s here?
What does ?s do in the following piece of code? import re, pprint text = open('books.xml').read() pattern = '(?s)isbn=(.*?).*?title(.*?)/title' found = re.findall(pattern, text) mapping = {isbn: title for (isbn, title) in found} pprint.pprint(mapping) Here is books.xml catalog book isbn=0-596-00128-2 titlePython amp; XML/title dateDecember 2001/date authorJones, Drake/author /book /catalog -- https://mail.python.org/mailman/listinfo/python-list
What does (?Pname) pattern syntax do?
What does ?P and part1 match in the following piece of code? re.search('(?Ppart1\w*)/(?Ppart2\w*)', '...aaa/bbb/ccc]').groups() -- https://mail.python.org/mailman/listinfo/python-list
What is description attribute in python?
What does description attribute in the following code mean? curs.execute('select * from people') colnames = [desc[0] for desc in curs.description] -- https://mail.python.org/mailman/listinfo/python-list
What does zip mean?
What does zip return in the following piece of code? curs.execute('select * from people') colnames = [desc[0] for desc in curs.description] rowdicts = [] for row in curs.fetchall(): rowdicts.append(dict(zip(colnames, row))) -- https://mail.python.org/mailman/listinfo/python-list
Re: What is description attribute in python?
curs is coming from the following piece of code import sqlite3 conn = sqlite3.connect('dbase1') curs = conn.cursor() -- https://mail.python.org/mailman/listinfo/python-list
What is rstrip() in python?
What is rstrip() in python? What does it do in the following piece of code? import sqlite3 conn = sqlite3.connect('dbase1') curs = conn.cursor() file = open('data.txt') rows = [line.rstrip().split(',') for line in file] -- https://mail.python.org/mailman/listinfo/python-list
Popen class?
What is Popen class? -- https://mail.python.org/mailman/listinfo/python-list
%%(%s)s mean in python
def fetchRecord(db, form): try: key = form['key'].value record = db[key] fields = record.__dict__ fields['key'] = key except: fields = dict.fromkeys(fieldnames, '?') fields['key'] = 'Missing or invalid key!' return fields def updateRecord(db, form): if not 'key' in form: fields = dict.fromkeys(fieldnames, '?') fields['key'] = 'Missing key input!' else: key = form['key'].value if key in db: record = db[key] else: from person import Person record = Person(name='?', age='?') for field in fieldnames: setattr(record, field, eval(form[field].value)) db[key] = record fields = record.__dict__ fields['key'] = key return fields db = shelve.open(shelvename) action = form['action'].value if 'action' in form else None if action == 'Fetch': fields = fetchRecord(db, form) elif action == 'Update': fields = updateRecord(db, form) else: fields = dict.fromkeys(fieldnames, '?') fields['key'] = 'Missing or invalid action!' db.close() print(replyhtml % htmlize(fields)) What does %%(%s)s mean in Python? -- https://mail.python.org/mailman/listinfo/python-list
Re: %%(%s)s mean in python
also what does rowshtml += (rowhtml % ((fieldname,) * 3)) expand to? -- https://mail.python.org/mailman/listinfo/python-list
What does %%(%s)s mean/expand to in Python? What does rowshtml += (rowhtml % ((fieldname, ) * 3)) expand to? Kindly explain.
def fetchRecord(db, form): try: key = form['key'].value record = db[key] fields = record.__dict__ fields['key'] = key except: fields = dict.fromkeys(fieldnames, '?') fields['key'] = 'Missing or invalid key!' return fields def updateRecord(db, form): if not 'key' in form: fields = dict.fromkeys(fieldnames, '?') fields['key'] = 'Missing key input!' else: key = form['key'].value if key in db: record = db[key] else: from person import Person record = Person(name='?', age='?') for field in fieldnames: setattr(record, field, eval(form[field].value)) db[key] = record fields = record.__dict__ fields['key'] = key return fields db = shelve.open(shelvename) action = form['action'].value if 'action' in form else None if action == 'Fetch': fields = fetchRecord(db, form) elif action == 'Update': fields = updateRecord(db, form) else: fields = dict.fromkeys(fieldnames, '?') fields['key'] = 'Missing or invalid action!' db.close() print(replyhtml % htmlize(fields)) What does %%(%s)s mean in Python? also what does rowshtml += (rowhtml % ((fieldname,) * 3)) expand to? -- https://mail.python.org/mailman/listinfo/python-list
% symbol in python
trthkeytdinput type=text name=key value=%(key)s rowhtml = 'trth%stdinput type=text name=%s value%%(%s)s\n what does % mean in first line of code and what does %%(%s)s mean in second line of code kindly explain -- https://mail.python.org/mailman/listinfo/python-list
Re: % symbol in python
import cgi, shelve, sys, os shelvename = 'class-shelve' fieldnames = ('name', 'age', 'job', 'pay') form = cgi.FieldStorage() print('Content-type: text/html') sys.path.insert(0, os.getcwd()) replyhtml = html titlePeople Input Form/title body form method=POST action=peoplecgi.py table trthkeytdinput type=text name=key value=%(key)s $ROWS$ /table p input type=submit value=Fetch, name=action input type=submit value=Update, name=action /form /body/html rowhtml = 'trth%stdinput type=text name=%s value=%%(%s)s\n' rowshtml = '' for fieldname in fieldnames: rowshtml += (rowhtml % ((fieldname, ) * 3)) replyhtml = replyhtml.replace('$ROWS$', rowshtml) def htmlize(adict): new = adict.copy() for field in fieldnames: value = new[field] new[field] = cgi.escape(repr(value)) return new def fetchRecord(db, form): try: key = form['key'].value record = db[key] fields = record.__dict__ fields['key'] = key except: fields = dict.fromkeys(fieldnames, '?') fields['key'] = 'Missing or invalid key!' return fields def updateRecord(db, form): if not 'key' in form: fields = dict.fromkeys(fieldnames, '?') fields['key'] = 'Missing key input!' else: key = form['key'].value if key in db: record = db[key] else: from person import Person record = Person(name='?', age='?') for field in fieldnames: setattr(record, field, eval(form[field].value)) db[key] = record fields = record.__dict__ fields['key'] = key return fields db = shelve.open(shelvename) action = form['action'].value if 'action' in form else None if action == 'Fetch': fields = fetchRecord(db, form) elif action == 'Update': fields = updateRecord(db, form) else: fields = dict.fromkeys(fieldnames, '?') fields['key'] = 'Missing or invalid action!' db.close() print(replyhtml % htmlize(fields)) -- https://mail.python.org/mailman/listinfo/python-list
Re: % symbol in python
import cgi, shelve, sys, os shelvename = 'class-shelve' fieldnames = ('name', 'age', 'job', 'pay') form = cgi.FieldStorage() print('Content-type: text/html') sys.path.insert(0, os.getcwd()) replyhtml = html titlePeople Input Form/title body form method=POST action=peoplecgi.py table trthkeytdinput type=text name=key value=%(key)s $ROWS$ /table p input type=submit value=Fetch, name=action input type=submit value=Update, name=action /form /body/html rowhtml = 'trth%stdinput type=text name=%s value=%%(%s)s\n' rowshtml = '' for fieldname in fieldnames: rowshtml += (rowhtml % ((fieldname, ) * 3)) replyhtml = replyhtml.replace('$ROWS$', rowshtml) def htmlize(adict): new = adict.copy() for field in fieldnames: value = new[field] new[field] = cgi.escape(repr(value)) return new def fetchRecord(db, form): try: key = form['key'].value record = db[key] fields = record.__dict__ fields['key'] = key except: fields = dict.fromkeys(fieldnames, '?') fields['key'] = 'Missing or invalid key!' return fields def updateRecord(db, form): if not 'key' in form: fields = dict.fromkeys(fieldnames, '?') fields['key'] = 'Missing key input!' else: key = form['key'].value if key in db: record = db[key] else: from person import Person record = Person(name='?', age='?') for field in fieldnames: setattr(record, field, eval(form[field].value)) db[key] = record fields = record.__dict__ fields['key'] = key return fields db = shelve.open(shelvename) action = form['action'].value if 'action' in form else None if action == 'Fetch': fields = fetchRecord(db, form) elif action == 'Update': fields = updateRecord(db, form) else: fields = dict.fromkeys(fieldnames, '?') fields['key'] = 'Missing or invalid action!' db.close() print(replyhtml % htmlize(fields)) kindly let me know what is $ROWS$ along with % symbol's meaning -- https://mail.python.org/mailman/listinfo/python-list
Re: % symbol in python
kindly let me know what does %%(%s)% mean -- https://mail.python.org/mailman/listinfo/python-list