Issue36480
Created on 2019-03-30 00:14 by 78Alpha, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Messages (5) | |||
|---|---|---|---|
| msg339164 - (view) | Author: 78 (78Alpha) | Date: 2019-03-30 00:14 | |
Using .strip() on windows leads to the first and last character of a word being deleted. Magenta.zip becomes agenta.zi |
|||
| msg339165 - (view) | Author: Eric V. Smith (eric.smith) * ![]() |
Date: 2019-03-30 00:51 | |
Please provide the exact code to duplicate the problem. I suspect this is a problem with your code, not with str.strip and not with Windows. |
|||
| msg339225 - (view) | Author: 78 (78Alpha) | Date: 2019-03-30 22:15 | |
import binascii
import os
import re
import sys
import hashlib
import json
import codecs
import threading
import datetime
from multiprocessing.pool import ThreadPool
try:
import PySimpleGUI_Custom as sg
except:
import PySimpleGUI as sg
import time
import multiprocessing
import sys
import pathlib
import random
import io
from PIL import Image
import base64
import multiprocessing
t1 = time.time()
settings = json.load(open("{}settings.txt".format(home_), 'r'))
security = True if settings["SECURITY"] == "True" else False
cpu_ = int(settings["THREADS"])
pool = ThreadPool(processes=int(cpu_))
comp_hash_other_2 = json.load(open('{}{}'.format(home_,
"Input_Data_Hash.txt"), 'r'))
comp_hash_other_ = json.load(open('{}{}'.format(home_,
"Output_Image_Hash.txt"), 'r'))
sort_n(name)
dig = 0
file_lim = len(name) - 1
file_len = len(name)
check = 0
b1 = 0
b2 = 0
b3 = 0
b4 = 0
for i in range(0, new_len):
event, values = main_window.Read(timeout=0)
if dig is file_len or event == "Button":
break
content = open("{}{}".format(input_, str(name[dig])), 'rb').read()
temp_name = str(name[dig]).strip("-{}.bmp".format(dig))
file_ = "{}{}".format(output_, str(temp_name))
open(file_, 'ab').write(content[96:])
dig += 1
progress_bar.UpdateBar(i)
progress_percent.Update(f"{i * 100 // new_len}%")
progress_bar.UpdateBar(current_count=1, max=1)
progress_percent.Update("100%")
check_value = dig / new_len
# The strip method works on all *Nix platforms without error, such
that magenta.zip is magenta.zip
# However, testing it on windows, magenta.zip was turned into agenta.zi
# Testing on Window: https://photos.app.goo.gl/uF1LVG2TyYk33UQy6
On Fri, Mar 29, 2019 at 5:51 PM Eric V. Smith <report@bugs.python.org>
wrote:
>
> Eric V. Smith <eric@trueblade.com> added the comment:
>
> Please provide the exact code to duplicate the problem.
>
> I suspect this is a problem with your code, not with str.strip and not
> with Windows.
>
> ----------
> nosy: +eric.smith
> status: open -> pending
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue36480>
> _______________________________________
>
|
|||
| msg339226 - (view) | Author: Eric V. Smith (eric.smith) * ![]() |
Date: 2019-03-30 22:34 | |
I cannot run that example on my computer.
Please reduce this to a single line of code, with no imports, that calls .strip() and shows your problem. Ideally you will just use constants, and not computed strings.
Something like:
>>> 'magenta.zip'.strip('pizamn')
'genta.'
And also, show that exact same line of code executed on both platforms.
That said, the problem is likely in your usage of .strip(). Please re-read the documentation: it does not remove substrings from a given string, it removes any of the given characters from the beginning and end of the string.
So, this is correct:
>>> 'magenta.zip'.strip('pm')
'agenta.zi'
You're probably seeing some difference due to upper or lower case filenames on the two platforms.
|
|||
| msg339235 - (view) | Author: 78 (78Alpha) | Date: 2019-03-31 01:02 | |
I have read the documentation. It didn't function near what I thought it did. I've never heard it stripping front and back characters in tutorials. I solely admit I was wrong in assuming its function. On Sat, Mar 30, 2019, 3:35 PM Eric V. Smith <report@bugs.python.org> wrote: > > Eric V. Smith <eric@trueblade.com> added the comment: > > I cannot run that example on my computer. > > Please reduce this to a single line of code, with no imports, that calls > .strip() and shows your problem. Ideally you will just use constants, and > not computed strings. > > Something like: > > >>> 'magenta.zip'.strip('pizamn') > 'genta.' > > And also, show that exact same line of code executed on both platforms. > > That said, the problem is likely in your usage of .strip(). Please re-read > the documentation: it does not remove substrings from a given string, it > removes any of the given characters from the beginning and end of the > string. > > So, this is correct: > >>> 'magenta.zip'.strip('pm') > 'agenta.zi' > > You're probably seeing some difference due to upper or lower case > filenames on the two platforms. > > ---------- > > _______________________________________ > Python tracker <report@bugs.python.org> > <https://bugs.python.org/issue36480> > _______________________________________ > |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:13 | admin | set | github: 80661 |
| 2021-03-02 20:08:55 | zach.ware | set | files: - tac.eml |
| 2021-03-02 19:59:20 | cfox9284 | set | files: + tac.eml |
| 2019-03-31 01:03:55 | eric.smith | set | status: open -> closed resolution: not a bug stage: resolved |
| 2019-03-31 01:02:13 | 78Alpha | set | messages: + msg339235 |
| 2019-03-30 22:34:59 | eric.smith | set | messages: + msg339226 |
| 2019-03-30 22:15:18 | 78Alpha | set | status: pending -> open messages: + msg339225 |
| 2019-03-30 00:51:57 | eric.smith | set | status: open -> pending nosy: + eric.smith messages: + msg339165 |
| 2019-03-30 00:14:47 | 78Alpha | create | |
