Where is the whitespace error in this code? - whitespace

user_word = input()
user_number = int(input())
User_word = 'Amy'
user_number = '5'
user_word = str(input('Amy,5'))
"the code above in the last section is where I am getting the whitespace error."

Related

do shell script with awk fails in AppleScript, but same awk command works in Terminal

Making a shell script work in AppleScript.
The following works in Terminal:
awk -F\" '/kMDItemTextContent/{print $2}' /Users/john/Desktop/PDFTags/mdimport.txt
But that same line, with do shell script, throws an error in Script Editor.
do shell script "awk -F\" '/kMDItemTextContent/{print $2}' /Users/john/Desktop/PDFTags/mdimport.txt"
This is from the Replies in Script Editor:
tell current application do shell script "awk -F\" '/kMDItemTextContent/{print $2}' /Users/john/Desktop/PDFTags/mdimport.txt"
--> error "sh: -c: line 0: unexpected EOF while looking for matching `\"' sh: -c: line 1: syntax error: unexpected end of file" number 2
For reference, here is the context of mdimport.txt
Imported '/Users/John/Desktop/PDFTags/Untitled.txt' of type 'public.plain-text' with plugIn /System/Library/Spotlight/RichText.mdimporter. 32 attributes returned {
":EA:_kMDItemUserTags" = (
);
":EA:kMDItemLastUsedDate" = "2020-11-07 08:17:13 +0000";
":MD:DeviceId" = 16777227;
":MD:kMDItemPath" = "/Users/john/Desktop/PDFTags/Untitled.txt";
"_kMDItemContentChangeDate" = "2020-11-05 23:24:57 +0000";
"_kMDItemCreationDate" = "2020-11-05 22:34:36 +0000";
"_kMDItemCreatorCode" = 0;
"_kMDItemDisplayNameWithExtensions" = {
"" = "Untitled.txt";
};
"_kMDItemFileName" = "Untitled.txt";
"_kMDItemFinderFlags" = 16;
"_kMDItemFinderLabel" = 0;
"_kMDItemFromImporter" = 1;
"_kMDItemIsExtensionHidden" = 1;
"_kMDItemIsFromImporter" = 1;
"_kMDItemLocked" = 1;
"_kMDItemOwnerGroupID" = 20;
"_kMDItemOwnerUserID" = 501;
"_kMDItemTextEncodingHint" = 134217984;
"_kMDItemTypeCode" = 0;
"com_apple_metadata_modtime" = "626311497.290109";
kMDItemAlternateNames = (
"Untitled.txt"
);
kMDItemContentCreationDate = "2020-11-05 22:34:36 +0000";
kMDItemContentModificationDate = "2020-11-05 23:24:57 +0000";
kMDItemContentType = "public.plain-text";
kMDItemContentTypeTree = (
"public.plain-text",
"public.text",
"public.data",
"public.item",
"public.content"
);
kMDItemDateAdded = "2020-11-07 08:56:45 +0000";
kMDItemDisplayName = {
"" = Untitled;
};
kMDItemDocumentIdentifier = 27837;
kMDItemKind = {
"" = NSStringPboardType;
ar = "\U0645\U0633\U062a\U0646\U062f \U0646\U0635\U064a \U0639\U0627\U062f\U064a";
ca = "Document de text sense format";
cs = "Prost\U00fd textov\U00fd dokument";
da = "Alm. tekstdokument";
de = "Reines Textdokument";
el = "\U0388\U03b3\U03b3\U03c1\U03b1\U03c6\U03bf \U03b1\U03c0\U03bb\U03bf\U03cd \U03ba\U03b5\U03b9\U03bc\U03ad\U03bd\U03bf\U03c5";
en = "Plain Text Document";
"en_AU" = "Plain Text Document";
"en_GB" = "Plain Text Document";
es = "Documento de texto sin formato";
"es_419" = "Documento de texto sin formato";
fi = "Pelkk\U00e4 teksti -dokumentti";
fr = "Document format texte";
"fr_CA" = "Document format texte";
he = "\U05de\U05e1\U05de\U05da \U05de\U05dc\U05dc \U05e4\U05e9\U05d5\U05d8";
hi = "\U092a\U094d\U0932\U0947\U0928 \U091f\U0947\U0915\U094d\U0938\U094d\U091f \U0926\U0938\U094d\U0924\U093e\U0935\U0947\U091c\U093c";
hr = "Dokument obi\U010dnog teksta";
hu = "Sima sz\U00f6veges dokumentum";
id = "Dokumen Teks Biasa";
it = "Documento di solo testo";
ja = "\U6a19\U6e96\U30c6\U30ad\U30b9\U30c8\U66f8\U985e";
ko = "\Uc77c\Ubc18 \Ud14d\Uc2a4\Ud2b8 \Ubb38\Uc11c";
ms = "Dokumen Teks Biasa";
nl = "Platte-tekstdocument";
no = "Dokument med ren tekst";
pl = "dokument tekstowy (zwyk\U0142y)";
pt = "Documento de Texto Simples";
"pt_PT" = "Documento de texto simples";
ro = "Document text simplu";
ru = "\U0414\U043e\U043a\U0443\U043c\U0435\U043d\U0442 \U043f\U0440\U043e\U0441\U0442\U043e\U0433\U043e \U0442\U0435\U043a\U0441\U0442\U0430";
sk = "Dokument s\U00a0oby\U010dajn\U00fdm textom";
sv = "Rent textdokument";
th = "\U0e40\U0e2d\U0e01\U0e2a\U0e32\U0e23\U0e02\U0e49\U0e2d\U0e04\U0e27\U0e32\U0e21\U0e18\U0e23\U0e23\U0e21\U0e14\U0e32";
tr = "D\U00fcz Metin Belgesi";
uk = "\U0414\U043e\U043a\U0443\U043c\U0435\U043d\U0442 \U043f\U0440\U043e\U0441\U0442\U043e\U0433\U043e \U0442\U0435\U043a\U0441\U0442\U0443";
vi = "T\U00e0i li\U1ec7u v\U0103n b\U1ea3n thu\U1ea7n t\U00fay";
"zh_CN" = "\U7eaf\U6587\U672c\U6587\U7a3f";
"zh_HK" = "\U7d14\U6587\U5b57\U6587\U4ef6";
"zh_TW" = "\U7d14\U6587\U5b57\U6587\U4ef6";
};
kMDItemLogicalSize = 345;
kMDItemPhysicalSize = 4096;
kMDItemTextContent = "Here are the text file contents that was used to test the routine.\n\nHash Tag Test Document\n\n#HashTag1 this is the first hash tag.\n#HashTag2 this is the second hash tag.\n\nThe following hash tag is inside and at the end of a paragraph:
#HashTag3\n\nThe next hash tag #HashTag4 is in the middle of a paragraph.\n\n#HashTag5\n#asdfasdfasdfasdfasfdasdfasd"; }
Looking at a portion of the error message:
unexpected EOF while looking for matching `\"'
It is referring to the field separator assigned by: -F
You need to, in this case, both single-quote and escape the single double-quote.
do shell script "awk -F'\"' '/kMDItemTextContent/{print $2}' /Users/john/Desktop/PDFTags/mdimport.txt"
Result:
"Here are the text file contents that was used to test the
routine.\n\nHash Tag Test Document\n\n#HashTag1 this is the first
hash tag.\n#HashTag2 this is the second hash tag.\n\nThe following
hash tag is inside and at the end of a paragraph:"

"for limit must be a number" error in roblox (Data Saving and Loading)

I leveled up my character and got some items, when i rejoined, it didn't load my previous data, It gave me level 0 and didn't load any items (it didn't give any output for level problem, but it gave this output for item problem: 'for' limit must be a number), but PLD.ItemNumber is a number, because It is from "ItemNumber" variable in the saving function. How to fix it? Code:
local DataStoreService = game:GetService("DataStoreService");
local PD = DataStoreService:GetDataStore("PlayerData");
function SaveData(Player)
local TableSave = {};
TableSave.Level = Player.PlayerData.Stats.Level.Value;
local TableItems = {};
local ItemNumber = 0;
for i,v in pairs(Player.PlayerData.Items:GetChildren()) do
ItemNumber = ItemNumber + 1;
TableItems["Item"..ItemNumber]={};
local TI = TableItems["Item"..ItemNumber];
TI.ItemName = v.Name;
TI.Level = v.Level.Value;
TI.Damage = v.Damage.Value;
end
table.insert(TableSave,TableItems);
TableSave.ItemNumber = ItemNumber;
PD:SetAsync(Player.userId,TableSave);
end
function LoadData(Player)
local success, err = pcall(function()
PLD = PD:GetAsync(Player.userId);
end)
if success then
Player.PlayerData.Stats.Level.Value = PLD.Level;
for i = 1,PLD.ItemNumber do
local CurrentItem = Instance.new("Folder");
CurrentItem.Name = PLD[1]["Item"..i].ItemName;
local Lv = Instance.new("IntValue");
Lv.Name = "Level";
Lv.Value = PLD[1]["Item"..i].Level;
Lv.Parent = CurrentItem;
local Dm = Instance.new("IntValue");
Dm.Name = "Damage";
Dm.Value = PLD[1]["Item"..i].Damage;
Dm.Parent = CurrentItem;
CurrentItem.Parent=Player.PlayerData.Items;
end
else
print("ERROR IN GET ASYNC");
end
end
game.Players.PlayerRemoving:Connect(function(plr)
repeat wait() until plr.PlayerData;
SaveData(plr);
end)
game.Players.PlayerAdded:Connect(function(plr)
repeat wait() until plr.PlayerData;
LoadData(plr);
end)

Error in rstudio coding

I running my corpus in Rstudio, it runs first and second line coding but generating error on third row.
s<- Corpus(DirSource("C:/Users/mazhar/Documents/Sindhicorpus", pattern = "*.txt")
Word <- wordcloud(words = names(term.freq),
freq = term.freq, min.freq = 1, random.order = F, colors = brewer.pal(8, "Dark2"))
The error is
Error: unexpected ',' in "freq = term.freq,"

python, import csv file, read columns and rows, remove blank spaces, convert strings to real numbers

I'm having trouble with importing a csv file into python and having it separate the information. I want to also remove all the blank spaces and convert the numbers (which are strings right now) into integers. Here is what I have so far. These lines work but do not accomplish the task of removing the blank spaces and converting the strings to integers.
filename = 'myfile.csv'
f = open(filename, 'r')
read = f.readlines()
print(read)
for i in range(len(read)):
read[i] = read[i].split(',')
print(read)
header = read[0]
print(header)
info = {}
cntr = 0
for name in header:
info[name] = [line[cntr] for line in read]
cntr += 1
print(info)
I searched through past examples on this forum and this is what I tried to do to have the blank spaces removed but now I'm lost:
import csv
aList = []
with open('myfile.csv', 'r') as f:
reader = csv.reader(f, skipinitialspace = True, delimiter = ',', quoting = csv.QUOTE_NONE)
for row in reader:
aList.append(row)
print(aList)
info = {}
cntr = 0
for i in aList:
info[aList] = [line[cntr] for line in reader]
cntr += 1
print(info)
#sample input
#1 23,456,789
#11 2,11 3,114
import csv
aList = []
with open('myfile.csv', 'r') as f:
reader = csv.reader(f, skipinitialspace = True, delimiter = ',', quoting = csv.QUOTE_NONE)
for row in reader:
aList.append(row)
print(aList)
info = {}
cntr = 0
print [map(int,[j.replace(" ","") for j in i]) for i in aList]
#[[123,456,789][112,113,114]]
Explanation - making the last line simple, and breaking into parts,
#[i for i in aList] gives [["1 23","456","789"]["11 2","11 3","114"]]
#[j.replace(" ","") for j in i] gives [["123","456","789"]["112","113","114"]]
#[map(int,[j.replace(" ","") for j in i]) for i in aList]
#maps all string in list to int and gives [[123,456,789][112,113,114]]

Remove the desired content from a text

I would like to get a working code to simply remove from a text line a specific part that always begins with "(" and finish with ")".
Sample text : Hello, how are you (it is a question)
I want to remove this part: "(it is a question)" to only keep this message "Hello, how are you"
Lost...
Thanks
One way using Regular Expressions;
input = "Hello, how are you (it is a question)"
dim re: set re = new regexp
with re
.pattern = "\(.*\)\s?" '//anything between () and if present 1 following whitespace
.global = true
input = re.Replace(input, "")
end with
msgbox input
If the part to be removed is always at the end of the string, string operations would work as well:
msg = "Hello, how are you (it is a question)"
pos = InStr(msg, "(")
If pos > 0 Then WScript.Echo Trim(Left(msg, pos-1))
If the sentence always ends with the ( ) section, use the split function:
line = "Hello, how are you (it is a question)"
splitter = split(line,"(") 'splitting the line into 2 sections, using ( as the divider
endStr = splitter(0) 'first section is index 0
MsgBox endStr 'Hello, how are you
If it is in the middle of the sentence, use the split function twice:
line = "Hello, how are you (it is a question) and further on"
splitter = split(line,"(")
strFirst = splitter(0) 'Hello, how are you
splitter1 = split(line,")")
strSecond = splitter1(UBound(Splitter1)) 'and further on
MsgBox strFirst & strSecond 'Hello, how are you and further on
If there is only one instance of "( )" then you could use a '1' in place of the UBound.
Multiple instances I would split the sentence and then break down each section containing the "( )" and concatenate the final sentence.

Resources