> that tells you the exact code line where the error occurred. No need to
> look around.
You are right:
try:
for line in f:
do_something()
except UnicodeDecodeError:
do_something_different()
does exactly what one would expect it to do.
Thank you very much for pointing this out
On Jul 26, 12:19 pm, wxjmfa...@gmail.com wrote:
> On Thursday, July 26, 2012 9:46:27 AM UTC+2, Jaroslav Dobrek wrote:
> > On Jul 25, 8:50 pm, Dave Angel <d...@davea.name> wrote:
> > > On 07/25/2012 08:09 AM, jarosla
> And the cool thing is: you can! :)
>
> In Python 2.6 and later, the new Py3 open() function is a bit more hidden,
> but it's still available:
>
> from io import open
>
> filename = "somefile.txt"
> try:
> with open(filename, encoding="utf-8") as f:
> for line in f:
On Jul 25, 8:50 pm, Dave Angel wrote:
> On 07/25/2012 08:09 AM, jaroslav.dob...@gmail.com wrote:
>
>
>
>
>
>
>
>
>
> > On Wednesday, July 25, 2012 1:35:09 PM UTC+2, Philipp Hagemeister wrote:
> >> Hi Jaroslav,
>
> >> you can catch a UnicodeDecodeError just like any other exception. Can
> >> you pr
On Wednesday, July 25, 2012 1:35:09 PM UTC+2, Philipp Hagemeister wrote:
> Hi Jaroslav,
>
> you can catch a UnicodeDecodeError just like any other exception. Can
> you provide a full example program that shows your problem?
>
> This works fine on my system:
>
>
> import sys
> open('tmp', 'wb').
Hello,
very often I have the following problem: I write a program that processes many
files which it assumes to be encoded in utf-8. Then, some day, I there is a
non-utf-8 character in one of several hundred or thousand (new) files. The
program exits with an error message like this:
UnicodeDec
Sorry, for code-historical reasons this was unnecessarily complicated.
Should be:
MY_DIR = '/my/path/to/dir'
FILES = os.listdir(MY_DIR)
def grep(regex):
output = []
for f in FILES:
command = "egrep " + '"' + regex + '" ' + MY_DIR + '/' + f
result = subprocess.getoutput(c
Hello,
I wrote the following code for using egrep on many large files:
MY_DIR = '/my/path/to/dir'
FILES = os.listdir(MY_DIR)
def grep(regex):
i = 0
l = len(FILES)
output = []
while i < l:
command = "egrep " + '"' + regex + '" ' + MY_DIR + '/' +
FILES[i]
result = s
Hello,
I would like to execute shell commands, but only if their execution
time is not longer than n seconds. Like so:
monitor(os.system("do_something"), 5)
I.e. the command do_somthing should be executed by the operating
system. If the call has not finished after 5 seconds, the process
should b
Hello,
when I have Python subtract floating point numbers it yields weird
results. Example:
4822.40 - 4785.52 = 36.87992
Why doesn't Python simply yield the correct result? It doesn't have a
problem with this:
482240 - 478552 = 3688
Can I tell Python in some way to do this differently?
Hello,
in Python3, I often have this problem: I want to do something with
every line of a file. Like Python3, I presuppose that every line is
encoded in utf-8. If this isn't the case, I would like Python3 to do
something specific (like skipping the line, writing the line to
standard error, ...)
L
11 matches
Mail list logo