String indices must be integers not str? What's going on here - syntax

My Code:I'm learning to write the basic intro to a finance program that I found on YouTube. All necessary packages have been installed and updated just to make sure. In line 19 using the get_data_yahoo function is the way I'm calling upon the stock variable wrong?
Thanks
I tried updating all packages involved, closing the program, tried to change the stock variable to read as an integer using int(stock) nothing has worked.

Related

What does a double-asterisk mean in a Visual FoxPro function call?

I'm trying to work with some Visual FoxPro 9.0 code written years ago by programmers now long gone. There are several uses of ALLTRIM() that include a double-asterisk in front of the field name being passed, such as:
fred = ALLTRIM( **barney )
where Barney is a character field in a table. When I try running that line in a VFP session, it errors out with "Function is missing )". But I'm uncomfortable supporting code that I don't understand - what does the "**" do?
I've tried storing the field to a memvar, in case there's a SCATTER in the code that calls this, with no change in the resulting error. I've tried storing other data types (numeric and boolean) to the memvar, still no change. I've been programming in dBase, then FoxBase, then FoxPro, then VFP, for almost 35 years - and I don't remember ever coming across this before. And yet, the program runs without errors, I just don't understand what it is doing.
In case any of this matters, the code in question is stored in a memo field in a table, then invoked with an EXECSCRIPT() call. And some of the tables that the code is working with (but not the one containing the code) are SQL Server tables, accessed through cursor adapters - so "barney" in my example is very likely a field in a cursor adapter, not a .DBF.
I found my answer. Searching for asterisks in source code was useless, of course, because of comments. But I finally thought, after posting this question, of searching for the string with surrounding quotes, and found that, before the code I was looking at was called with EXECSCRIPT(), it was also run through STRTRAN(), which substituted "m." or "." or some other appropriate prefix for the "**" in the code.
So, the double asterisk was internal to the application, and meant nothing to VFP itself.

Expression.Error for Text.InferNumberType wasn't recognized

I've got a function where I want to determine if all the digits after the first are numbers. To do so, I thought I could use Text.InferNumberType which, per the documentation, should raise an error if the text is not a number.
Here is my code snippet:
a= Text.Start(Argument,1),
b= Text.End(Argument, Text.Length(Argument) - 1),
c= try Text.InferNumberType(b) otherwise "FALSE" ,
Instead, I'm getting this Expression.Error which says:
Expression.Error: the name Text.InferNumberType wasn't recognized. Make sure it's spelled correctly.
I literally copied and pasted the function name from the reference document, so I'm sure it's spelled correctly.
I'm using PowerQuery in Excel 2013. PowerQuery was installed about a week ago using the latest download from Microsoft. I did search and found this question - I'm wondering if this is a similar issue? I don't see anything in the documentation though which says this function wouldn't be available in certain versions of power query.
This is likely an older function that isn't supported in Excel 2013. I'd recommend a different function like Number.From or Number.FromText, which have similar functionality.

Object name becoming lowercase

I have some code which has worked in multiple installations for about a year. Today im doing a small change to a control and then another control seems to have developed an issue. When at runtime im getting a 91 error object variable or with block variable not set.
I therefore looked at the problem line which is: -
If Screen.ActiveForm.name = "frmFoutmelding" Then Exit Sub
so I noticed the name was lowercase. if i delete .name and rehit the "dot" then it shows me i can use .Name but as soon as i move from this line it drops back to .name
I've checked for instances of name and it appears everywhere in the code in different modules but i cant find if i have accidentally defined this lowercase name anywhere?
Googling doesn't seem to show much but i feel Im googling the wrong terms
chaps - thanks for your suggestions - this was the first instance of the lowercase name and searching as Jim suggested didn't reveal anything I'm afraid. What I did discover was that this was suddenly being run before any forms had actually been displayed and so the count was 0. I therefore, did an on error to check the form count and exit the sub if it =0 then if not to carry on with the line I thought I was having issues with.
It's likely that you did create a new variable or property called (lower case) name, or that some included reference did the same. It's possible to use reserved words as variable names in some cases, but it requires taking specific steps.
I would first search your code for instances of name As to see if you created a variable (this assumes you use Option Explicit, which is a must IMO). Then search for Property*name with * as a wildcard.
If those fail you could try unchecking references or components to see if any of them define name. If none of that finds anything, please post back here.
Jim Mack covers a lot of the potential issues. I think another is if you typed a lower case '.name' in association with Activeform at some point earlier in the same code module - the VB6 IDE checks in the current module and uses that to define what case to use. Look further up the same code module (sub or function).
Ultimately, check what changes you made by comparing the old source to the new in a file comparison tool like windiff - you do have backups, right?

How to reference and run a python document from the python interpreter

I just want to be able to run a python script from the interpreter, so that I can work on my changes to my script in notepad or other editor, save, and then interactively test changed code in the python interpreter.
Also, IDLE is not a solution. I'm operating on a government computer that is blocking the port it uses to communicate interaction between console and module.
To clear up any confusion, here's a demonstration of what I'm trying to do:
So, how do I do it?
EDIT:
Okay so I found a statement that does what I want. exec(open('dir').read()). The problem I think is that the directory I want to refer to contains periods. But I'm sure this will work, because open('dir').read() produces a string of the contents of a document specified, as long as I reference the likes of C:\myTest.py, and exec() obviously runs strings as input. So how can I reference files from the location I want?
Okay so the problem seems to be that Windows addresses often contain what python sees as 'unicode exits'. I'm not sure what they do or how they work, but I know they start with \ and are followed by a single letter and that there are enough of them to use up half the alphabet. There are a few solutions but only one is worth a damn for this application. I came across an operator that can be used in conjunction with strings, similarly to how + can be used to concatenate multiple strings, it seems r or R if you prefer (interestingly), can be used immediately before a string to tell the interpreter to take the string 'literally' as a string, and nothing else.
One would think that the quotes would be enough to express this, but they aren't and I'll probably eventually find out why. But for now, here's the answer to my question. I hope someone else finds it useful:
In plain text: >>> exec(open(R'C:\Users\First.Last\Desktop\myScript.py').read())

Erlang and current date time

I would like to get a current date time with erlang.
I have tried using the code below;
{{Year,Month,Day},{Hour,Min,Sec}} = erlang:localtime().
But sometimes it got an error like '** exception error: no match of right hand side value {{2012,5,6},{23,40,58}}'
Looks like there is a problem with 1 digit. I try searching couple of webs but still cannot find a way to cope this.
I believe this is quite an easy one but as a erlang newbie, I cannot resolve this. I try my best.
Env:
Erlang {"OTP APN 181 01","R15B01"} installed with windows binary version
Windows XP
Thanks in advance,
No, there is no problem with 1 digit. It should match perfectly well (check with {{Year,Month,Day},{Hour,Min,Sec}} = {{2012,5,6},{23,40,58}}). Most likely you have already assigned one of the variables to something earlier in the function.

Resources