Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #48496
| From | Νίκος <support@superhost.gr> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Why 'files.py' does not print the filenames into a table format? |
| Date | 2013-06-17 09:11 +0300 |
| Organization | National Technical University of Athens, Greece |
| Message-ID | <kpm99p$250s$4@news.ntua.gr> (permalink) |
| References | <kpifru$3kp$3@news.ntua.gr> <mailman.3401.1371325647.3114.python-list@python.org> <kpigkm$1j17$1@news.ntua.gr> <mailman.3407.1371328673.3114.python-list@python.org> <kpm8hg$250s$3@news.ntua.gr> |
On 17/6/2013 8:58 πμ, Νίκος wrote:
> On 15/6/2013 11:37 μμ, Joshua Landau wrote:
>> On 15 June 2013 20:51, Nick the Gr33k <support@superhost.gr> wrote:
>>> On 15/6/2013 10:46 μμ, Jarrod Henry wrote:
>>>>
>>>> Nick, at this point, you need to hire someone to do your work for you.
>>>
>>>
>>> The code is completely ready.
>>> Some detail is missing and its not printing the files as expected.
>>
>> Look, Nick,
>>
>> A lot of people are frustrated by you. You should understand that. If
>> you cannot, you need to step back and consider, or you really are a
>> troll.
>>
>> Now, obviously it's not going to get you any help to have half of the
>> forum angry at you. People have stopped helping, at least in large.
>> This is fine; people here are volunteers. But you want help.
>>
>> So, Nick, listen. You need to learn how to ask *smart* questions. If
>> you do, I *guarantee* that people will respect you a lot more. I'll be
>> willing to give a bit of time to explain what I mean.
>>
>> 1) What is your problem. Not "I want to know why it doesn't print
>> anything." Here's an example, for some random idea:
>>
>>> I've written some code to find the first file in a directory which
>>> is not UTF-8. Lines 40-42 are meant to print out the file found
>>> to a log ("/home/joshua/.logs/log"). Unfortunately, although
>>> there is no error, no file is printed to the log.
>>
>> 2) What have you tried? What debugging have you done? For someone of
>> your skill level, it's also important to tell us what you think your
>> code is doing. Example:
>>
>>> I've tried checking for a failure - when there is no non-UTF-8 file
>>> in the directory the appropriate error is raised. I think this should
>>> mean that the "else" after the "for" loop would be run, and this
>>> should run the lines 40-42 above when there *is* a non-UTF-8
>>> file.
>>
>> 3) If possible, give us an example we can run.
>>
>>> To make helping easier, I've removed the code that searches the
>>> directory as I know that works, and instead there's a list of BytesIO
>>> and StringIO objects that pretend to be them. The bug is still
>>> there.
>>
>> Do you see the difference?
>>
>>> Irrelevant to my question i just noticed weird behavior about my
>>> pelatologio.py script which can be seen here:
>>>
>>> http://superhost.gr/?show=stats
>>>
>>> The first 3 files are of my doing.
>>> All the rest are of someone else's that managed to append entries
>>> into my
>>> counters database utilizing this code:
>>>
>>> ================
>>>
>>> try:
>>> #find the needed counter for the page URL
>>> cur.execute('''SELECT ID FROM counters WHERE url =
>>> %s''',
>>> page )
>>> data = cur.fetchone() #URL is unique, so
>>> should only
>>> be one
>>>
>>> if not data:
>>> #first time for page; primary key is
>>> automatic, hit
>>> is defaulted
>>> cur.execute('''INSERT INTO counters (url)
>>> VALUES
>>> (%s)''', page )
>>> cID = cur.lastrowid #get the primary key
>>> value of the new record
>>> ======================
>>>
>>> Does someone want to state something?
>>
>> Sure. Here I go:
>>
>> What's the question?
>
>
> I DID, I FINALLY DID IT JUST NOW!!
>
> HERE ARE THE MODIFICATIONS THAT MADE IT HAPPEN!
>
>
> ==========================================================================================================
>
> # Convert wrongly encoded filenames to utf-8
> ==========================================================================================================
>
>
> path = b'/home/nikos/public_html/data/apps/'
> filenames = os.listdir( path )
>
> utf8_filenames = []
>
> for filename in filenames:
> # Compute 'path/to/filename'
> filename_bytes = path + filename
> encoding = guess_encoding( filename_bytes )
>
> if encoding == 'utf-8':
> # File name is valid UTF-8, so we can skip to the next file.
> utf8_filenames.append( filename_bytes )
> continue
> elif encoding is None:
> # No idea what the encoding is. Hit it with a hammer until it
> stops moving.
> filename = filename_bytes.decode( 'utf-8', 'xmlcharrefreplace' )
> else:
> filename = filename_bytes.decode( encoding )
>
> # Rename the file to something which ought to be UTF-8 clean.
> newname_bytes = filename.encode('utf-8')
> os.rename( filename_bytes, newname_bytes )
> utf8_filenames.append( newname_bytes )
>
> # Once we get here, the file ought to be UTF-8 clean and the
> Unicode name ought to exist:
> assert os.path.exists( newname_bytes.decode('utf-8') )
> ================================
>
> i SMASHED MY HEAD INTO THE WALL, BUT I MADE IT!!!!
> FINALLY AFTER > 15 DAYS!!
>
> FEEL FREE TO CONGRATULATE ME!
oups!
everything work as expected but not the part when the counter of a
filename gets increased when the file have been requested.
I don't see how since:
if filename:
#update file counter
cur.execute('''UPDATE files SET hits = hits + 1, host = %s, lastvisit =
%s WHERE url = %s''', (host, lastvisit, filename) )
--
What is now proved was at first only imagined!
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Why 'files.py' does not print the filenames into a table format? Nick the Gr33k <support@superhost.gr> - 2013-06-15 22:38 +0300
Re: Why 'files.py' does not print the filenames into a table format? Jarrod Henry <jarrodhenry@gmail.com> - 2013-06-15 14:46 -0500
Re: Why 'files.py' does not print the filenames into a table format? Nick the Gr33k <support@superhost.gr> - 2013-06-15 22:51 +0300
Re: Why 'files.py' does not print the filenames into a table format? Benjamin Schollnick <benjamin@schollnick.net> - 2013-06-15 16:29 -0400
Re: Why 'files.py' does not print the filenames into a table format? Joshua Landau <joshua.landau.ws@gmail.com> - 2013-06-15 21:37 +0100
Re: Why 'files.py' does not print the filenames into a table format? Νίκος <support@superhost.gr> - 2013-06-17 08:58 +0300
Re: Why 'files.py' does not print the filenames into a table format? Νίκος <support@superhost.gr> - 2013-06-17 09:11 +0300
Re: Why 'files.py' does not print the filenames into a table format? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-17 07:00 +0000
Re: Why 'files.py' does not print the filenames into a table format? Simpleton <support@superhost.gr> - 2013-06-17 12:07 +0300
Re: Why 'files.py' does not print the filenames into a table format? Simpleton <support@superhost.gr> - 2013-06-17 12:18 +0300
Re: Why 'files.py' does not print the filenames into a table format? Simpleton <support@superhost.gr> - 2013-06-17 13:26 +0300
Re: Why 'files.py' does not print the filenames into a table format? Chris Angelico <rosuav@gmail.com> - 2013-06-16 08:51 +1000
Re: Why 'files.py' does not print the filenames into a table format? Nick the Gr33k <support@superhost.gr> - 2013-06-16 04:07 +0300
Python Greek mailing list [was Re: Why 'files.py' does not print the filenames into a table format?] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-16 05:06 +0000
Re: Python Greek mailing list [was Re: Why 'files.py' does not print the filenames into a table format?] Nick the Gr33k <support@superhost.gr> - 2013-06-16 11:28 +0300
Re: Python Greek mailing list [was Re: Why 'files.py' does not print the filenames into a table format?] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-16 10:33 +0000
Re: Python Greek mailing list [was Re: Why 'files.py' does not print the filenames into a table format?] Ferrous Cranus <support@superhost.gr> - 2013-06-16 13:57 +0300
Re: Python Greek mailing list [was Re: Why 'files.py' does not print the filenames into a table format?] Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-06-16 12:09 +0100
Re: Python Greek mailing list [was Re: Why 'files.py' does not print the filenames into a table format?] Ferrous Cranus <support@superhost.gr> - 2013-06-16 14:12 +0300
Re: Python Greek mailing list [was Re: Why 'files.py' does not print the filenames into a table format?] Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2013-06-16 13:19 +0200
Re: Python Greek mailing list [was Re: Why 'files.py' does not print the filenames into a table format?] Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2013-06-16 13:03 +0200
Re: Why 'files.py' does not print the filenames into a table format? Ferrous Cranus <support@superhost.gr> - 2013-06-16 16:57 +0300
Re: Why 'files.py' does not print the filenames into a table format? Nick the Gr33k <support@superhost.gr> - 2013-06-16 04:10 +0300
Re: Why 'files.py' does not print the filenames into a table format? Nick the Gr33k <support@superhost.gr> - 2013-06-16 04:24 +0300
Re: Why 'files.py' does not print the filenames into a table format? Grant Edwards <invalid@invalid.invalid> - 2013-06-17 14:50 +0000
Re: Why 'files.py' does not print the filenames into a table format? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-06-15 22:29 +0100
Re: Why 'files.py' does not print the filenames into a table format? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-16 00:10 +0000
Re: Why 'files.py' does not print the filenames into a table format? alex23 <wuwei23@gmail.com> - 2013-06-16 17:04 -0700
Re: Why 'files.py' does not print the filenames into a table format? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-06-17 01:31 +0100
Re: Why 'files.py' does not print the filenames into a table format? Nick the Gr33k <support@superhost.gr> - 2013-06-16 04:03 +0300
Re: Why 'files.py' does not print the filenames into a table format? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-06-16 02:10 +0100
Re: Why 'files.py' does not print the filenames into a table format? Nick the Gr33k <support@superhost.gr> - 2013-06-16 04:28 +0300
Re: Why 'files.py' does not print the filenames into a table format? Denis McMahon <denismfmcmahon@gmail.com> - 2013-06-16 07:23 +0000
Re: Why 'files.py' does not print the filenames into a table format? Nick the Gr33k <support@superhost.gr> - 2013-06-16 11:35 +0300
Re: Why 'files.py' does not print the filenames into a table format? Denis McMahon <denismfmcmahon@gmail.com> - 2013-06-16 08:55 +0000
Re: Why 'files.py' does not print the filenames into a table format? Ferrous Cranus <support@superhost.gr> - 2013-06-16 16:59 +0300
Re: Why 'files.py' does not print the filenames into a table format? jmfauth <wxjmfauth@gmail.com> - 2013-06-16 05:57 -0700
csiph-web