invalid syntax error while reading text file - printing

trying to write and read.
Text is written in the file but while reading I get "invalid syntax" on the print line:
Thank you
text_file = open ("write_to_file.txt", "w")
t = input( "enter name ")
a = input ("address ")
enter code here`n =input ("number ")
text_file.write(t)
text_file.write(a)
text_file.write(n)
text_file.close()
text_file = open("write_to_file.txt", "r")
print text_file.read()
text_file.close()

Related

DXL error not undestood :DXL: <D:\XXXX.dxl:1234> Un module en cours est requis pour lopération => US traduction = operation requires a current module

I have following error message :
DEBUG: isBaseline(spec_produit) = true -R-E- DXL: <D:\XXXX.dxl:1234> Un module en cours est requis pour lopération
US traduction = operation requires a current module
line 1234 is the following : print "DEBUG: baseline loaded for " name(module_in_database) " = " major(baseline_open) "." minor(baseline_open) suffix(baseline_open) "\n"
With : baseline_open = baselineInfo(module_in_database) (=true)
I don't understand why I have this message as I already use this kind of coding elsewhere with success.
Here I have the message in a loop that I use to detect if I have still open module after having close all open modules (I don't know why I still have open module but it is another subject)
the loop is :
// display list of open module at then end of the script
for module_in_database in database do
{
logResult = logResult "INFO: open modules at the end the script are " fullName(module_in_database) "\n"
// display more information on open modules : (DEBUG) :
print "DEBUG: isBaseline(" name(module_in_database) ") = " isBaseline(module_in_database) "\n"
baseline_open = baselineInfo(module_in_database)
if (baseline_open != null) {
print "DEBUG: baseline loaded for" name(module_in_database) " = " major(baseline_open) "." minor(baseline_open) suffix(baseline_open) "\n"
} else {
print "DEBUG: " name(module_in_database) " = CURRENT \n"
}
}
Version 1:
Module module_in_database
Baseline baseline_open
string logResult = ""
// display list of open module at then end of the script
for module_in_database in database do
{
logResult = logResult "INFO: open modules at the end the script are " fullName(module_in_database) "\n"
if type (module_in_database) == "Formal" then {
// display more information on open modules : (DEBUG) :
print "DEBUG: isBaseline(" name(module_in_database) ") = " isBaseline(module_in_database) "\n"
baseline_open = baselineInfo(module_in_database)
if (baseline_open != null) {
current = module_in_database // <------ set current module so that the next line works!
print "DEBUG: baseline loaded for" name(module_in_database) " = " major(baseline_open) "." minor(baseline_open) suffix(baseline_open) "\n"
} else {
print "DEBUG: " name(module_in_database) " = CURRENT \n"
}
} else {
print fullName(module_in_database) " is a Link Module. No baselineInfo available\n"
}
}
Version 2:
Module module_in_database
Baseline baseline_open
string logResult = ""
ModuleVersion mv
string version_string
// display list of open module at then end of the script
for module_in_database in database do
{
logResult = logResult "INFO: open modules at the end the script are " fullName(module_in_database) "\n"
if type (module_in_database) == "Formal" then {
// display more information on open modules : (DEBUG) :
print "DEBUG: isBaseline(" name(module_in_database) ") = " isBaseline(module_in_database) "\n"
mv = moduleVersion (module_in_database)
version_string = versionString (mv) // <---- don't use "major" and "minor", instead use version_string, which does not require a "current" module
if (version_string != "") {
print "DEBUG: baseline loaded for" name(module_in_database) " = " version_string "\n"
} else {
print "DEBUG: " name(module_in_database) " = CURRENT \n"
}
} else {
print fullName(module_in_database) " is a Link Module. No baselineInfo available\n"
}
}
P.S: Having read through our thread again, I think that the misunderstanding stems from DOORS' inconsistency when naming things. a "current version" is a Module which is not a baseline. A "current module" in DOORS-speak is a module version that is "the one '''module''' that the user currently interacts with". When you have opened five windows with modules (either current version or baselines or link modules), only one of these windows is at the front - only one of these windows catches your keyboard input - and that window contains the "current" Module. If you have a one-liner like print fullName (current Module) and you open the database explorer (main window), click on Tools->Edit DXL… and paste the code, it will complain that no Module is current. if you then click on one window and in this window click on Tools->Edit DXL…, you will get the SAME DXL window, but now the code will run, because now DOORS knows which Module is the one that you mean when you say fullName (current Module).
Unfortunately, that's still not correctly said: the current Module is not directly related to the window at the front - you might even have opened Modules invisibly. And using DXL you can say "this invisible Module is the current one" although there is a window at the front showing a different Module.
It's complicated but I hope that I explained it correctly now.
Strange.
I have been able to run the script with the following declarations
Module module_in_database
Baseline baseline_open
string logResult = ""
and I got the expected results.
I remember some problems with perms that expect a current module even though they shouldn't.
Perhaps you just need to add some lines to your loop
if type (module_in_database) == "Formal" then {
current = module_in_database
} else {
continue
}
but still, that should not be necessary

Could not load project, Xcode 7.3.1 [duplicate]

I have just localized the file Localizable.strings in my Xcode project in order to localise my application to a few different languages. However, having edited each of the files in the standard "key = value" format, I receive the following parsing error, which does not specify a file making it hard to track down what it is referring to.
CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon in dictionary on line 10. Parsing will be abandoned. Break on _CFPropertyListMissingSemicolon to debug.
I have looked through each of the *.strings files, specifically on line 10, and I found nothing of any interest or regards as to what is causing the issue. Please can you tell me where I am going wrong.
Here is a sample of a Localizable.strings file in my project. All other files follow the same format.
"Enter URL" = "Voer adres in"
"Headers" = "Koppen"
"Key" = "sleutel"
"Value" = "waarde"
"Parameters" = "Parameters"
"Tap to add a new line" = "Tik om een nieuwe lijn toe te voegen"
"Perform request" = "Verzoek Uitvoeren"
"Response" = "Antwoord"
"Received Headers" = "Ontvangen Koppen"
"Error" = "Fout"
"Loading" = "Verzoek aan het versturen"
I then use NSLocalizedString() to provide the translated string.
As stated in the error message, you're missing semicolons at the end of each line.
"foo" = "bar";
Is the correct format
"Enter URL" = "Voer adres in";
"Headers" = "Koppen";
"Key" = "sleutel";
"Value" = "waarde";
"Parameters" = "Parameters";
"Tap to add a new line" = "Tik om een nieuwe lijn toe te voegen";
"Perform request" = "Verzoek Uitvoeren";
"Response" = "Antwoord";
"Received Headers" = "Ontvangen Koppen";
"Error" = "Fout";
"Loading" = "Verzoek aan het versturen";
this is the correct formula
This message can also be come due to use of :(colon) instead of ;(semicolon) at line end. Please be sure there is semicolon(;) at each end of line and also there is no colon(:) also.
Swift 4
make sure the one for all Apps file for Localizable.strings don't make more than one page just one
local.string English "hi" = "hi";
local.string Arabic "hi" = "هاي";
using
and put this extension in your app
extension String {
var localizedLized: String {
return NSLocalizedString(self, comment: "")
}
}
In my case the error was caused by a missing quotation mark.
"CFBundleDisplayName" = myTestApp";

Parsing response.getEntity(String.class) string to xml with DocumentHelper.parseText() in dom4j

dom4j has no trouble doing
String text = "<person> <name>James</name> </person>";
Document document = DocumentHelper.parseText(text);
What I need is this
String text = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"+
"<person> <name>James</name> </person>";
Document document = DocumentHelper.parseText(text);
But it throws an exception.
org.dom4j.DocumentException: Error on line 1 of document : parsing initialization error: org.gjt.xpp.XmlPullParserException: only whitespace content allowed outside root element at line 1 and column 1 seen
I find the problem. The before line below is the one that fails. The after line works.
BEFORE
Document output = DocumentHelper.parseText(response.getEntity(String.class));
AFTER
Document output = DocumentHelper.parseText(response.getEntity(String.class).trim());

Build CSV from parse files python

I am building a small database (for personal use), from over a 1000 files. I am looking for specific word, but the issue that I have if the word is not contained in the file how can i write a NoData line, what I would like to have is:
Africa Botswana test 51.1922546 -113.9366341
Africa Kenya Skydive Kenya -13.788388 33.78498
Africa Malawi Skydive Malawi NoData NoData
Africa Mauritius SkyDive Austral 30.5000854 -8.824510574
Africa Morocco Beni Mellal NoData NoData
for i in os.listdir(Main_Path):
if "-" in i:
for filename in os.listdir(Main_Path+i):
if ".dat" in filename and os.path.isdir(Main_Path+i):
f_split = filename.split("-")
if len(f_split) == 4:
continent.append(f_split[0])
country.append(f_split[1])
state.append(f_split[2].split(".")[0])
else:
continent.append(f_split[0])
country.append("")
state.append(f_split[1].split(".")[0])
d = open(Main_Path+i+"/" + filename, "r")
files = d.readlines()
d.close()
for k, line in enumerate(files):
if "Dropzone.com :" in line:
dzname.append(line.split(":")[1].strip())
elif 'id="lat"' in line:
lat.append(line.split("=")[3].split('"')[1].strip())
myFile = open(Main_Path+"MYFILE.csv", "wb")
wtr= csv.writer( myFile )
for a,b,c,d,e in zip(continent,country,state,dzname,lat):
wtr.writerow([a,b,c,d,e])
myFile.close()
I am stack "elif 'id="lat"' in line:" because it adds to the list "lat" only the files which contains id = lat. I do understand why but I would like the parser to return and add to the list an NoData
sorry i wrote the question from another comp.
Do you mean something like this?
That is: if no line in files contains id="lat" it will append "No Data" to lat.
snip...
d = open(Main_Path+i+"/" + filename, "r")
files = d.readlines()
d.close()
found_latitude = False
for k, line in enumerate(files):
if "Dropzone.com :" in line:
dzname.append(line.split(":")[1].strip())
elif 'id="lat"' in line:
found_latitude = True
lat.append(line.split("=")[3].split('"')[1].strip())
if not found_latitude:
lat.append("No Data")
snip...

Formatting not working in 4gl [ USING clause ]

I was trying to format the output variable as follows:
Scenario 1:
LET msg = "Roopesh Majeti here "
Empno Using "&&&&&"
Call Logmsg(msg)
In this scenario, the empno get formatted to 5 digits [ I should say spaces ] and gets displayed.
Scenario 2:
Let c_check = "&&"
Let msg ="Roopesh Majeti here"
Empno using c_check
Call Logmsg(msg)
Here, my expectation is that, whatever is the value of c_check [ say 10 &'s ] then the empno should be formatted to 10 positions/spaces.
But it's not working as expected.
Am I missing anything here?
You don't say what you do get, which makes it hard to know how it is not working.
You have some minor syntax errors, missing the commas after the constant strings.
You don't show the declaration of msg or c_check; could the problem be that the message is being truncated?
What do you get when you use:
DISPLAY "<<", msg CLIPPED, ">>"
DISPLAY "<<", msg, ">>"
You should be able to show us a complete program like this, and its output:
MAIN
DEFINE msg CHAR(64)
DEFINE c_check CHAR(20)
DEFINE empno INTEGER
LET empno = 12345
LET msg = "Roopesh Majeti here ", empno Using "&&&&&"
DISPLAY "<<", msg CLIPPED, ">>"
DISPLAY "<<", msg, ">>"
LET empno = 987654321
LET c_check = "&&"
LET msg ="Roopesh Majeti here", empno USING c_check
DISPLAY "<<", msg CLIPPED, ">>"
DISPLAY "<<", msg, ">>"
END MAIN

Resources