I want to display an output with Test = 0 using Fortran, I tried to use:
'WRITE(11,*) 'Test =' testdata'
Assuming 11 is correct and testdata is a parameter that is being calculated.
I wasn't able to get the output and there was an error.
Anyone have any idea why it is so?
Try inserting a comma and deleting the apostrophes:
WRITE(11,*) 'Test =', testdata
If you had reported what the error message you saw was I might have made this answer more apposite.
Related
I have the following html extract
0.94
I am trying to read the href value ie 0.94.I tried the following :
answer = browser.find_element_by_class_name("res")
print answer
output = answer.get_attribute('data-href')
print output
The Result is as follows:
None
I tried various other methods, using find_element_by_xpath etc,but not able to get the desired value ie. 0.94 (as in this example).
How can I get this value in the shortest way? Thanks in advance
Use getText method if you want to to print 0.94
I have this piece of code
i want that if anything is entered other than 1,2,3,4 to take input once again
import msvcrt
answer = msvcrt.getch()
while answer not in ['1','2','3','4']:
answer = msvcrt.getch('Enter a valid option (1,2,3,4): ')
entering anything that is not in the list gives this Error:
TypeError: getch() takes exactly 0 arguments (1 given)
but I dont know why its giving me this error tho
any help is appreciated
The error text is self explanatory. In the second line you called getch correctly:
answer = msvcrt.getch()
In order for the code to do what it's expected change it to:
while answer not in ['1','2','3','4']:
print 'Enter a valid option (1,2,3,4): '
answer = msvcrt.getch()
The error message means exactly what it says: msvcrt.getch() is a function that takes no arguments.
You called it with one argument here:
answer = msvcrt.getch('Enter a valid option (1,2,3,4): ')
If you want to print a prompt, then use a separate print call first.
This line believes you are trying to pass a value to getch which is not allowed.
answer = msvcrt.getch('Enter a valid option (1,2,3,4): ')
documentation: https://docs.python.org/2/library/msvcrt.html
While your first use of getch is fine, the second use will throw an error.
When I run the below code it prints out a calendar for an entire year (which I don't want). I want it to write to file but it won't. It also returns the error message TypeError: expected a character buffer object. Also, casting it into a string doesn't work.
import calendar
cal = calendar.prcal(2015)
with open('yr2015.txt', 'w') as wf:
wf.write(cal)
As an example, the below code prints one month of a year and returns a string, but this isn't what I want
print calendar.month(2015, 4)
print type(calendar.month(2015, 4))
So when I run the below code I get the error message <type 'NoneType'>. It seems to me that it should be a string but obviously isn't. Any suggestions on how I can get a 12-month calendar into a text file?
print type(calendar.prcal(2015))
prcal doesn't return anything. Use cal = calendar.TextCalendar().formatyear(2015) Instead.
Your question is a bit confusing. However, you don't have to make python write to the file.
Let python write to stdout and redirect stdout to a file
python myCal.py > yr2015.txt
This should do the trick
That is because calendar.prcal() will only print the calendar of an year. And it wont return you any values. So this line in your code print type(calendar.prcal(2015)) will return none type error.
Ive been following the tutorial on how to use mallet in R to create topic models. My text file has 1 sentence per line. It looks like this and has about 50 sentences.
Thank you again and have a good day :).
This is an apple.
This is awesome!
LOL!
i need 2.
.
.
.
This is my code:
Sys.setenv(NOAWT=TRUE)
#setup the workspace
# Set working directory
dir<-"/Users/jxn"
Dir <- "~/Desktop/Chat/malletR/text" # adjust to suit
require(mallet)
documents1 <- mallet.read.dir(Dir)
View(documents1)
stoplist1<-mallet.read.dir("~/Desktop/Chat/malletR/stoplists")
View(stoplist1)
**mallet.instances <- mallet.import(documents1$id, documents1$text, "~/Desktop/Chat/malletR/stoplists/en.txt", token.regexp ="\\p{L}[\\p{L}\\p{P}]+\\p{L}")**
Everything works except for the last line of the code
**`**mallet.instances <- mallet.import(documents1$id, documents1$text, "~/Desktop/Chat/malletR/stoplists/en.txt", token.regexp ="\\p{L}[\\p{L}\\p{P}]+\\p{L}")**`**
I keep getting this error :
Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, :
java.lang.NoSuchMethodException: No suitable method for the given parameters
According to the package, this is how the function should be:
mallet.instances <- mallet.import(documents$id, documents$text, "en.txt",
token.regexp = "\\p{L}[\\p{L}\\p{P}]+\\p{L}")
I believe it has something to do with the token.regexp argument as
documents1 <- mallet.read.dir(Dir) works just fine which means that the first 3 arguments supplied to mallet.instances was correct.
This is a link to the git repo that i was following the tutorial from.
https://github.com/shawngraham/R/blob/master/topicmodel.R
Any help would be much appreciated.
Thanks,
J
I suspect the problem is with your text file. I have encountered the same error and resolved it by using the as.character() function as follows:
mallet.instances <- mallet.import(as.character(documents$id),
as.character(documents$text),
"en.txt",
FALSE,
token.regexp="\\p{L}[\\p{L}\\p{P}]+\\p{L}")
Are you sure you converted the id field also to character ? It is easy to overlook the advice and leave it as an integer.
Also there is a typo in the code sample: the backslashes have to be escaped:
token.regexp = "\\p{L}[\\p{L}\\p{P}]+\\p{L}"
This usually occurs because the html text editor eats up one backslash.
I have this code:
msgs = int(post['time_in_weeks'])
for i in range(msgs):
tip_msg = Tip.objects.get(week_number=i)
it always results in an error saying that no values could be found.
week_number is an integer field. When I input the value of i directly,
the query works.
When i print out the value of i I get the expected values.
Any input at all would be seriously appreciated.
Thanks.
The range function will give you a zero based list of numbers up to and excluding msgs. I guess there is no Tip with week_number=0.
Also, to limit the number of queries you could do this:
for tip in Tip.objects.filter(week_number__lt=msgs):
#do something
or, if you want specific weeks:
weeks=(1,3,5)
for tip in Tip.objects.filter(week_number__in=weeks):
#do something