double backslashes in printed strings --- is by convention (a \ must be escaped with a \ )
when i write code below , i'm getting the path including double backslashes . How do I get rid of extra backslash?
#######
import sys
import codecs
print sys.path
sys.path.
print sys.path
path1 = u"Users\
print path1
for list in open(path1,"r"):
print list
#######
and i get below in the message box.
#######
u'C:\\Program Files\\
Users\system99\
[error] script [ temp6 ] stopped with error in line 8
[error] IOError ( (2, 'No such file or directory', 'Users\
#######
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- SikuliX Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- furni
- Solved:
- Last query:
- Last reply:
Revision history for this message
|
#1 |
The double \ are only in the printout (according to the need to escape a \ with the escape character \). I guess this is to be prepared for copy&paste. The strings themself internally are correct.
why do you think, you need that?
path1 = u"Users\
path1 = r"Users\
should be sufficient.
your problem:
[error] IOError ( (2, 'No such file or directory', 'Users\
a relative path is looked for in the current working directory, but I guess you mean:
path1 = r"c:\Users\
Revision history for this message
|
#2 |
Thanks for answering, Raiman!
>The double \ are only in the printout (according to the need to escape a \ with the escape character \). I guess this is to be >prepared for copy&paste. The strings themself internally are correct.
>
>why do you think, you need that?
I'm really new to Sikuli or python, and thought the backslash was mandatory.
>path1 = u"Users\
>path1 = r"Users\
>should be sufficient.
>
>your problem:
>[error] IOError ( (2, 'No such file or directory', 'Users\
>
>a relative path is looked for in the current working directory, but I guess you mean:
>path1 = r"c:\Users\
I changed the path1 to path1 = r"c:\Users\
But when there are chinese characters in the path, still get an error. :((
#######
import sys
import codecs
path1 = u"D:\\依頼分\
print path1
for list in codecs.
print list.encode(
#######
and i get the error below
#######
D:\依頼分\
[error] script [ temp6 ] stopped with error in line 5
[error] IOError ( (2, 'No such file or directory', 'D:\\\xe4\
[error] --- Traceback --- error source first line: module ( function ) statement 881: codecs ( open ) IOError: (2, 'No such file or directory', 'D:\\\xe4\
[error] --- Traceback --- end --------------
Revision history for this message
|
#3 |
this works with version 1.1.0 on Windows 10 64 with Java 8 (should work on Win7, 8 and Java 7 too):
data = u"c:\SikuliX\
dir = os.path.
uprint("*** content of " + dir)
for fname in os.listdir(dir):
uprint(fname)
uprint("*** content of " + data)
ftxt = open(data)
for line in ftxt.readlines():
uprint(
... and prints out:
*** content of c:\SikuliX\依頼分
sikuli.funcあ.txt
*** content of c:\SikuliX\
sikuli.funcあ line 1
sikuli.funcあ line 2
sikuli.funcあ line 3
Revision history for this message
|
#4 |
Thanks for such a quick reply!! :)))
but I still get errors below :(
#######
data = u"C:\Users\
dir = os.path.
uprint("*** content of " + dir)
for fname in os.listdir(dir):
uprint(fname)
uprint("*** content of " + data)
ftxt = open(data)
for line in ftxt.readlines():
uprint(
#######
and print out..
#######
[error] script [ third ]] stopped with error at line --unknown--
[error] Could not evaluate error source nor reason. Analyze StackTrace!
[error] java.lang.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
a:2524)
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.sikuli.
at org.sikuli.
at org.sikuli.
java.lang.
#######
Im running it on Win7 32bit java version "1.8.0_60" Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) Client VM (build 25.60-b23, mixed mode, sharing)
Plenty of errors.... I'm confused :(((
Revision history for this message
|
#5 |
What SikuliX version?
How do you run the script?
Revision history for this message
|
#6 |
The version is sikulixsetup-
Im running it from Sikuli IDE by typing r+CTRL
When double clicking runsikuli.cmd to start sikuli IDE, i get the message below in the command prompt.
+++ running this Java
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) Client VM (build 25.60-b23, mixed mode, sharing)
+++ trying to run SikuliX
+++ using: -Xms64M -Xmx512M -Dfile.
C:\Users\
10 10, 2015 9:41:52 午前 java.util.
WARNING: Could not open/create prefs root node Software\
x80000002. Windows RegCreateKeyEx(...) returned error code 5.
[info] HotkeyManager: add Capture Hotkey: CTRL+SHIFT 2 (50, 3)
[info] HotkeyManager: add Abort Hotkey: ALT+SHIFT C (67, 9)
[error] IDE: Remembered window not valid. Going to primary screen
Is this related to the error??
Revision history for this message
|
#7 |
no.
please upgrade to final version 1.1.0
Revision history for this message
|
#8 |
I upgraded to final version! but still get errors. ...
########
data = u"C:\Users\
dir = os.path.
uprint("*** content of " + dir)
for fname in os.listdir(dir):
uprint(fname)
uprint("*** content of " + data)
ftxt = open(data)
for line in ftxt.readlines():
uprint(
########
and print out
[error] script [ FIRST ]] stopped with error at line --unknown--
[error] Could not evaluate error source nor reason. Analyze StackTrace!
[error] java.lang.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
a:2524)
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.sikuli.
at org.sikuli.
at org.sikuli.
java.lang.
##########
awwww
Revision history for this message
|
#10 |
import os
import sys
import codecs
data = u"C:\\Users\
print data
dir = os.path.
uprint("*** content of " + dir)
for fname in os.listdir(
uprint(fname)
uprint("*** content of " + data)
for line in codecs.
print line.encode(
##################
print out
##################
C:\Users\
*** content of C:\Users\
FIRST.sikuli
SECOND.sikuli
sikuli_funcあ.txt
新しいテキスト ドキュメント - コピー (2).txt
新しいテキスト ドキュメント - コピー (3).txt
新しいテキスト ドキュメント - コピー (4).txt
新しいテキスト ドキュメント - コピー.txt
新しいテキスト ドキュメント.txt
*** content of C:\Users\
##################
i did it! but still don't get the content of sikuli_funcあ.txt :((
Revision history for this message
|
#11 |
if you go back to my recommendation at comment #3, then vital things you did might be:
import codecs
data = u"c:\SikuliX\
dir = os.path.
uprint("*** content of " + dir)
for fname in os.listdir(dir):
uprint(fname)
uprint("*** content of " + data)
ftxt = codecs.
for line in ftxt.readlines():
uprint(
Revision history for this message
|
#12 |
I got nothing
#########
*** content of c:\SikuliX\依頼分
#########
awww
Revision history for this message
|
#13 |
i got an error only by writing #-*-coding:utf-8-*- at the first line in the script
the error message is...
#######
[error] script [ FORTH ]] stopped with error at line --unknown--
[error] Could not evaluate error source nor reason. Analyze StackTrace!
[error] java.lang.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.sikuli.
at org.sikuli.
at org.sikuli.
onRun$1.
java.lang.
Revision history for this message
|
#14 |
like you said before, u and .encode("utf-8") of data = u"C:\\Users\
#########
import os
import sys
import codecs
#data = u"C:\\Users\
data = "C:\\Users\
print data
dir = os.path.
uprint("*** content of " + dir)
for fname in os.listdir(
uprint(fname)
uprint("*** content of " + data)
for line in codecs.
print line.encode(
#########
print out
#########
C:\Users\
*** content of C:\Users\
FIRST.sikuli
FORTH.sikuli
SECOND.sikuli
sikuli_funcあ.txt
THIRD.sikuli
新しいテキスト ドキュメント - コピー (2).txt
新しいテキスト ドキュメント - コピー (3).txt
新しいテキスト ドキュメント - コピー (4).txt
新しいテキスト ドキュメント - コピー.txt
新しいテキスト ドキュメント.txt
*** content of C:\Users\
#########
when writing the script below ..
#########
#coding: utf-8
print [u"こんにちは"]
print [u"こんにちは"
print ["こんにちは"]
#########
i get this
#########
[u'\u3053\
['\xe3\
['\xe3\
Revision history for this message
|
#15 |
hey RaiMan! I got it finally!!!
##########
import os
import sys
import codecs
#data = u"C:\\Users\
data1 = u"C:\\Users\
data = r"C:\Users\
print data
#dir = os.path.
dir = os.path.
print [dir]
uprint("*** content of " + dir)
#for fname in os.listdir(
for fname in os.listdir(dir):
uprint(fname)
for line in codecs.
uprint("*** content of ***" + line.encode(
##########
print out
##########
C:\Users\
[u'C:\\
*** content of C:\Users\
FIFTH.sikuli
FIRST.sikuli
FORTH.sikuli
SECOND.sikuli
sikuli_funcあ.txt
THIRD.sikuli
新しいテキスト ドキュメント - コピー (2).txt
新しいテキスト ドキュメント - コピー (3).txt
新しいテキスト ドキュメント - コピー (4).txt
新しいテキスト ドキュメント - コピー.txt
新しいテキスト ドキュメント.txt
*** content of ***部品 type number 年月
##########
when outputing to message box , the characters have to be utf-8 but when handing over the variable to the function, the string has to be unicode.