The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Python
 Problem with german "Umlaute" in string

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Stefan_Wak Posted - 07/23/2020 : 02:05:50 AM
Hello,
i worte a small script for importing a text file with spyder-ide. The path of this file contains "Prüfstände".
The script starts with # -*- coding: utf-8 -*- and also spyder shows the uft-8 encoding in the status bar.
When running the script in Origin 2020b (9.7.5.184) the following FileNotFoundError appears.
file = open(filename, 'r')
FileNotFoundError: [Errno 2] No such file or directory: 'S:/.../Prüfstände/...'

Running the same script with Origin 2021 (9.8.0.62) the script works fine.

Is there a setting in Origin 2020b to handle this problem or how has the filname to be defined, to handle the äöüß and is working with Origin 2020b.

Thanks, Stefan
4   L A T E S T    R E P L I E S    (Newest First)
cpyang Posted - 07/24/2020 : 09:52:39 AM
Thanks for the details, now we understand.

Before 2021, Origin's "run -pyf" command had a bug that it will not recognize py file encoding and always load as ANSI.

We fixed this in 2021 beta1 (ORG-22158-P1) so going forward, Origin will default to load py file as utf-8. Microsoft made a change to Notepad default to utf-8 without BOM at the end of 2018.

In order for your ANSI py to work in both 2020b and 2021, we can add a new switch to that run command, which will be ignored by 2020b, like

run -pyfa "test_import_ext.py"

to load it as ANSI in 2021.

CP

Stefan_Wak Posted - 07/24/2020 : 07:47:15 AM
Ok, i changed the encoding (with notepad++) to ANSI.
Now it is working.
Spyder shows "LATIN-1" and Origin Code Builder shows "Wester European".
Stefan_Wak Posted - 07/24/2020 : 04:51:11 AM
I am using Embedded Python.
I was unsing the command window, script window and also Python-console. All throw the same error, but in the script wondow is got a slightly other string (ok, it is just an other font, when i copy the output to the same texteditor, the output is the same...)

I changed the script to use OriginExt and it is running with spyder (ide).
When i try the same script from Origin with the following command, it fails with the same error.

run -pyf "test_import_ext.py"

File "C:\Users\was2liz\Documents\OriginLab\User Files\test_import_ext.py", line 39, in import_ess_file
    file = open(filename, 'r')
FileNotFoundError: [Errno 2] No such file or directory: 'S:/Q-Bereiche/Transfer/Prüfstände/F51 CRIN4 ESS/VA 2020/INV200351/ST1/Inj_20213 ST1-1.TXT'


Embedded Python: running with Origin failed.

# -*- coding: utf-8 -*-
"""
Created on Wed Jul 22 14:15:23 2020
@author: Stefan
"""
import PyOrigin        # Origin Funktionen

class ESS_Import():
    DELIMITER = ';'
    HEADER_LINES = 2
    SPACES = 2
    INJ_PRAEFIX = "Messung 00  Inj.Nr.: "
    INJ_LENGTH = 5
    DATE_START = len(INJ_PRAEFIX) + INJ_LENGTH + SPACES
    DATE_LEN = 10
    TIME_START = DATE_START + DATE_LEN + SPACES
    TIME_LEN = 8

    def __init__(self):
            self.import_ess_file("S:\Q-Bereiche\Transfer\Prüfstände\F51 CRIN4 ESS\VA 2020\INV200351\ST1\Inj_20213 ST1-1.TXT")

    def import_ess_file(self, filename):
        data = []
        filename = filename.replace("\\", "/")
        file = open(filename, 'r')
        lines = file.readlines()
        for line in lines:
            innerlist = line.split(self.DELIMITER)
            data.append(innerlist)
        self.data = data
        self.extract_data()
        self.check_data()
    def check_data(self):
        pass
    def extract_data(self):
        pass

def init_workbooks(e):
    mBookName = "ST1"
    messungen = PyOrigin.Pages(mBookName)
    if messungen == None:
        messungen = PyOrigin.CreatePage(PyOrigin.PGTYPE_WKS, mBookName,
                                        'Origin', 1)
    cntSheets = PyOrigin.Pages(mBookName).Layers.GetCount()
    for books in range(cntSheets, e.etc_count):
        PyOrigin.Pages(mBookName).AddLayer()
    for books in range(0, len(PyOrigin.Pages(mBookName))):
        messungen.Layers(books).SetName(f"KL_{books+1}")
def main():
    e = ESS_Import()
    init_workbooks(e)
    # TODO
    pass
if __name__ == "__main__":
    main()


With originExt, started with Spyder (IDE), working fine :-)

# -*- coding: utf-8 -*-
"""
Created on Wed Jul 22 14:15:23 2020
@author: Stefan
"""
#import PyOrigin        # Origin Funktionen
import OriginExt as O

class ESS_Import():
    DELIMITER = ';'
    HEADER_LINES = 2
    SPACES = 2
    INJ_PRAEFIX = "Messung 00  Inj.Nr.: "
    INJ_LENGTH = 5
    DATE_START = len(INJ_PRAEFIX) + INJ_LENGTH + SPACES
    DATE_LEN = 10
    TIME_START = DATE_START + DATE_LEN + SPACES
    TIME_LEN = 8

    def __init__(self):
            self.import_ess_file("S:\Q-Bereiche\Transfer\Prüfstände\F51 CRIN4 ESS\VA 2020\INV200351\ST1\Inj_20213 ST1-1.TXT")

    def import_ess_file(self, filename):
        data = []
        filename = filename.replace("\\", "/")
        file = open(filename, 'r')
        lines = file.readlines()
        for line in lines:
            innerlist = line.split(self.DELIMITER)
            data.append(innerlist)
        self.data = data
        self.extract_data()
        self.check_data()

    def check_data(self):
        pass

    def extract_data(self):
        pass

def init_workbooks(e):
    mBookName = "ST1"
    Oapp = O.Application()
    messungen = Oapp.Pages(mBookName)
    if messungen == None:
        messungen = Oapp.CreatePage(2, mBookName,
                                        'Origin', 1)
    cntSheets = Oapp.Pages(mBookName).Layers.GetCount()
    for books in range(cntSheets, e.etc_count):
        Oapp.Pages(mBookName).AddLayer()
    for books in range(0, len(Oapp.Pages(mBookName))):
        Oapp.Pages(mBookName).Layers(books).SetName(f"KL_{books+1}")
    Oapp.Save(r'c:\temp\test_1.opju')
    Oapp.Exit()

def main():
    e = ESS_Import()
    init_workbooks(e)
    # TODO
    pass

if __name__ == "__main__":
    main()
cpyang Posted - 07/23/2020 : 11:04:41 AM
Are you using Embedded Python? or using from outside of Origin?

CP


The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000