"TypeError: __init__() missing 3 required positional arguments" is the error I'm getting but I have answered all the arguments, what am I doing wrong - python-3.9

I have answered all the arguments what am I doing wrong. I am also new at this so I could have made a very obvious error, thanks for your help.
error message
Traceback (most recent call last):
File "C:\Users\cogli\PycharmProjects\inkling\classses_pt2.py", line 4, in <module>
stu = data(input("name, ") + input("major, ") + input("gpa, ") + input("is_on_probation "))
TypeError: __init__() missing 3 required positional arguments: 'major', 'gpa', and 'is_on_probation'
code
from classes import data
#stu = data(input("name, " + "major, " + "gpa, " + "is_on_probation "))
stu = data(input("name, ") + input("major, ") + input("gpa, ") + input("is_on_probation "))
print(stu.name)
import file
class data:
def __init__(self, name, major, gpa, is_on_probation):
self.name=name
self.major=major
self.gpa=gpa
self.is_on_probation=is_on_probation
outcome
name, ian
major, physics
gpa, 4.0
is_on_probation False
Traceback (most recent call last):
File "C:\Users\cogli\PycharmProjects\inkling\classses_pt2.py", line 4, in <module>
stu = data(input("name, ") + input("major, ") + input("gpa, ") + input("is_on_probation "))
TypeError: __init__() missing 3 required positional arguments: 'major', 'gpa', and 'is_on_probation'
I'm using python 3.9 to do this.

input("name, ") + input("major, ") + input("gpa, ") + input("is_on_probation ") returns a single string because the + operator concatenates strings. In Python, the syntax to separate arguments to a function uses a comma, so you should do
stu = data(input("name, "), input("major, "), input("gpa, "), input("is_on_probation "))

Related

Cypress: Assign and access global variable in cypress

I'm new with cypress, I tried to set several global variables to use for different purposes. However, the scope of those variables are different even they are declared as global. My expectation is output 3: 0 and 4 and 1, how could I do that? Thanks everyone, my code as below:
var totalCouponCredit = []
var arrayGameCredit = []
var totalSelectedCredit, userUsedCredit, gameCredit
describe ('Testing',function(){
it('Login',function(){
cy.get('div.row.flex-lg-column.h-100>div:nth-of-type(1)>div>div>h6').then(($selectedCredit)=>{
//This is the string return "SELECTED CREDITS 0/4", userUsedCredit is 0 and totalSelectedCredit is 4 after split
totalCouponCredit = $selectedCredit.text().match(/[a-zA-Z]+|[0-9]+(?:\.[0-9]+|)/g)
userUsedCredit = parseInt(totalCouponCredit[2])
totalSelectedCredit = parseInt(totalCouponCredit[3])
cy.get('div.col>p:nth-of-type(1)>span>span').then(($gameCredit)=>{
//This is the string return "This title is worth 1 credit(s)", gameCredit is 1 after split
arrayGameCredit = $gameCredit.text().match(/[a-zA-Z]+|[0-9]+(?:\.[0-9]+|)/g)
gameCredit = parseInt(arrayGameCredit[4])
cy.log("Out put 1:" + userUsedCredit + " and " + totalSelectedCredit + " and " +gameCredit)
})
cy.log("Out put 2:" + userUsedCredit + " and " + totalSelectedCredit + " and " +gameCredit)
})
cy.log("Out put 3:" + userUsedCredit + " and " + totalSelectedCredit + " and " +gameCredit)
})
})
OUTPUT:
Output 1: 0 and 4 and 1
Output 2: 0 and 4 and undefined
Output 3: undefined and undefined and undefined

How can I do a line break (line continuation) in Kotlin

I have a long line of code that I want to break up among multiple lines. What do I use and what is the syntax?
For example, adding a bunch of strings:
val text = "This " + "is " + "a " + "long " + "long " + "line"
There is no symbol for line continuation in Kotlin. As its grammar allows spaces between almost all symbols, you can just break the statement:
val text = "This " + "is " + "a " +
"long " + "long " + "line"
However, if the first line of the statement is a valid statement, it won't work:
val text = "This " + "is " + "a "
+ "long " + "long " + "line" // syntax error
To avoid such issues when breaking long statements across multiple lines you can use parentheses:
val text = ("This " + "is " + "a "
+ "long " + "long " + "line") // no syntax error
For more information, see Kotlin Grammar.
Another approach is to go for the 3 double quotes "" pairs i.e. press the double quotes 3 times to have something like this.
val text = """
This is a long
long
long
line
""".trimIndent()
With this approach you don't have to use + , \n or escape anything; just please Enter to put the string in the next line.
trimIndent() to format multi-line strings - Detects a common minimal indent of all the input lines, removes it from every line and also removes the first and the last lines if they are blank (notice difference blank vs empty).

Python 3.4 Multiprocess throws TypeError("cannot serialize '_io.BufferedReader' object",)

Recently I wrote a multiprocess code in Python 3.4 to download some images, it's working blazingly fast at first, then I get the following error and cannot start the program anymore.
Traceback (most recent call last):
File "multiprocessing_d.py", line 23, in <module>
main()
File "multiprocessing_d.py", line 16, in main
p.map(download, lines)
File "/usr/local/lib/python3.4/multiprocessing/pool.py", line 260, in map
return self._map_async(func, iterable, mapstar, chunksize).get()
File "/usr/local/lib/python3.4/multiprocessing/pool.py", line 608, in get
raise self._value
multiprocessing.pool.MaybeEncodingError: Error sending result: '<multiprocessing.pool.ExceptionWithTraceback object at 0x7f1e047f32e8>'. Reason: 'TypeError("cannot serialize '_io.BufferedReader' object",)'
My code is as following
download_helper.py
import sys
import os
from pathlib import Path
url_prefix = r"Some prefix"
def setup_download_dir(dictionary):
download_dir = Path(dictionary)
if not download_dir.exists():
download_dir.mkdir()
return dictionary
def download_link(dictionary, line):
from urllib.request import urlretrieve
itemid = line.split()[0].decode()
link = line.split()[1].decode()
if (link.startswith("http")):
image_url = link
else:
image_url = url_prefix + link
if os.path.isfile(dictionary + "/" + itemid + ".jpg"):
#print("Already have " + itemid + ".jpg")
pass
else:
urlretrieve(image_url, dictionary + "/" + itemid + ".jpg")
multiprocessing_d.py
from functools import partial
from multiprocessing.pool import Pool
import sys
from time import time
from download_helper import setup_download_dir, download_link
def main():
file_path = sys.argv[1]
dic_path = sys.argv[2]
download_dir = setup_download_dir(dic_path)
download = partial(download_link, download_dir)
with open(file_path, 'rb') as f:
lines = f.readlines()
ts = time()
p = Pool(processes=16, maxtasksperchild=1)
p.map(download, lines)
p.close()
p.join()
print('Took {}s'.format(time() - ts))
f.close()
if __name__ == "__main__":
main()
I've tried to search online but didn't find much information useful. My suspect is that there might be some exception raised in urlretrieve, but I don't know how to debug it. Any comments or suggestions would be appreciated!!
James

Python Hex to Ascii

How can I make Python loop through a file and convert the hex to ascii? The problem is that when Python loops through the file it sees \n and does not parse the file.
import binascii
fo = open('test.doc', 'r')
print fo.readlines()
dataFormatHex = binascii.a2b_hex ("%s" %fo)
output = ""
for char in dataFormatHex:
if char in string.printable: output += char
else: output += "."
print "\n" + output
The error trace is:
Traceback (most recent call last):
File "C:\Python27\hex2ascii-looper.py", line 7, in <module>
dataFormatHex = binascii.a2b_hex ("%s" %fo)
TypeError: Non-hexadecimal digit found
Here is what is in the test.doc:
140000003700000027000000260000006D0000008E000000040000002E000000000000001D00000003000000410000004D0000005800000094000000880000005E0000004F00000040000000360000007B000000660000005A00000042000000300000002F0000004300000048000000050000000C0000004900000044000000220000002D000000180000003800000011000000010000001500000009000000640000008100000020000000700000006C00000087000000650000000F000000610000005D0000001F000000210000001900000079000000690000008A0000008D0000002A0000008C00000073000000330000003B000000680000006F000000800000000E000000020000004A0000005900000039000000740000001C00000012000000060000001E000000830000006B0000006A000000750000000A0000007A00000023000000550000007E000000340000001B0000001700000084000000520000007700000092000000470000009300000076000000710000004600000060000000720000002B000000530000001A000000900000007D00000016000000670000008B00000063000000450000002C00000035000000070000005B00000050000000910000002900000086000000310000003A0000000D0000007F000000560000002400000054000000890000006E00000085000000950000008F0000004C0000007800000062000000570000003D0000000B00000010000000130000002500000032000000820000004E0000005C0000003F000000080000004B000000280000005F0000003C000000510000003E000000FFFFFFFF
310032002D00310038002D00310034005F004D0065007800690063006F0020006D0061006300680069006E006500730020006F007500740020006F006600200064006100740065002D006E00650077002E0078006C00730078000000D00032000000000000000000000031322D31382D31345F4D657869636F206D616368696E6573206F7574206F6620646174652D6E65772E786C73782E6C6E6B00900008000400EFBE00000000000000002A00000000000000000000000000000000000000000000000000310032002D00310038002D00310034005F004D0065007800690063006F0020006D0061006300680069006E006500730020006F007500740020006F006600200064006100740065002D006E00650077002E0078006C00730078002E006C006E006B00000040000000
6300620074006E005F0070007900740068006F006E005F003000350020002D002000530074006100740065006D0065006E00740073002C00200044006F00630075006D0065006E0074006100740069006F006E002C00200061006E0064002000480065006C0070002E0066006C0076000000F2003200000000000000000000006362746E5F707974686F6E5F3035202D2053746174656D656E74732C20446F63756D656E746174696F6E2C20616E642048656C702E666C762E6C6E6B0000A60008000400EFBE00000000000000002A000000000000000000000000000000000000000000000000006300620074006E005F0070007900740068006F006E005F003000350020002D002000530074006100740065006D0065006E00740073002C00200044006F00630075006D0065006E0074006100740069006F006E002C00200061006E0064002000480065006C0070002E0066006C0076002E006C006E006B0000004C000000
Just use .strip() on your string, it will remove the trailing \n.
import binascii
f = open(yourFile)
for line in f.readlines():
print(binascii.a2b_hex("%s" % (line.strip()))
f.close()

How to display fields in new line in same textBox in telerik reporting?

I am using Silverlight4 and Telerik Reporting Q3 2011. I am trying to Generate Reports of all Outlets. I used Table to display its fields. And I want to Display Full Address in same cell. How could I?
I Used following Experession to display Full Address in same cell.
= Fields.AddressLine1
+ ", " + Fields.AddressLine2
+ ", " + Fields.Suburb
+ ", " + Fields.City
+ ", " + Fields.State
+ ", " + Fields.Country
I want do display this in same cell but want output like below..
=====================
Address
=====================
15A,
xxxx xxxRoad,
xxxxxx,
xxxxxxxx
====================
But I m getting this
=====================
Address
=====================
15A, xxxx xxxRoad, xxxxxx, xxxxxxxx
=====================
How do I get Output Which I want?
made the Function NewLineFeeds() in this function I used Replace() Method to replace the specific string to newLine(\n) .
public static string NewLineFeeds(string text)
{
string result = text.Replace(", ", "\n");
result = result.Replace(", ", "\n");
result = result.Replace(", ", "\n");
return result;
}
and my Expression is
=NewLineFeeds(Fields.AddressLine1
+ ", " + Fields.AddressLine2
+ ", " + Fields.Suburb
+ ", " + Fields.City
+ ", " + Fields.State
+ ", " + Fields.Country)
This call the Function NewLineFeeds() and replace ", " to \n (new Line). Add this will work Fine..

Resources