my python functions do not work in jupyter notebook - python

i have written lines of code that run normally in jupyter notebook (here is the code below):
umd_departments = requests.get("https://api.umd.io/v0/courses/departments")
umd_departments_list = umd_departments.json()
umd_departments_list2 = json.dumps(umd_departments_list, indent=1)
department_storage = [department['dept_id'] for department in umd_departments_list]
print(department_storage)
the code above usually gives me the output i want and prints it out immediately. the issue i run into is when i try and put the code above into a function of its own it doesn't work
def get_UMD_departments():
umd_departments = requests.get("https://api.umd.io/v0/courses/departments")
umd_departments_list = umd_departments.json()
umd_departments_list2 = json.dumps(umd_departments_list, indent=1)
department_storage = [department['dept_id'] for department in umd_departments_list]
print(department_storage)
the problem i face with this version of code is that it never prints out anything as oppose to the other code i showed. with this code, i also don't get an error when i run it since the * symbol doesn't show up and i don't get an error message. so i'm not sure what the problem is. it usually just shows how many times i ran the cell. i was wondering if anyone knew a way to make the function version of my code to work, greatly appreciated.

Related

TypeError: 'dict_keys' object is not callable

I have used the below program to get the maximum and minimum value in a dictionary. But, there is an type error.
I am running the below code on Jupyter notebook and getting the type error as the 'dict.keys' object is not callable. same code runs successfully on the pycharm.
Please advise me what changes should I make so that the code runs successfully on the jupyter notebook?
what is wrong in my code? Code run on JupyterNBcode run on Pycharm successfully
I have tested your program in Jupyter Notebook and the code is working just fine. Maybe you check for any typos. Hope this help
Code snippet run on jupyter notebook
Yup I can run your code perfectly too. Please try to simplify it like below.
It looks better too.
my_dict = {'x':500, 'y':5874, 'z': 560}
key_max = max(my_dict, key = my_dict.get)
key_min = min(my_dict, key = my_dict.get)
print('Maximum Value: ',my_dict[key_max])
print('Minimum Value: ',my_dict[key_min])

PyWinAuto with out using "child_window"

I have NO return on child_window when the program is in its state i expect to work in.
I need a way to edit the text field but literally all examples and google searches i have done show no examples of implementation EXCEPT when using child_window
this should put Test into the edit field
from pywinauto.application import Application
app = Application(backend="uia").connect(title="DaVinci Resolve Studio - Template")
#app.DaVinciResolveStudioTemplate.print_control_identifiers()
Title = app.DaVinciResolveStudioTemplate.['TitleEdit', 'Edit8'].wrapper_object()
Title.type_keys("Test")
it returns a syntax error
I have read teh documentation and i HONESTLY have no idea how to initiate the return with out a child window. Googing "no child_window" with multiple iterations has yielded me hours wasted and NOT ONE solution.
if text is entered the child_window appears in returns, but that isnt how the program start's
This is the native return
please, explain it for me how im supposed to seach/grab/interact with out child window? with a example please because this has me at a loss
Syntax error is in line Title = app.DaVinciResolveStudioTemplate.['TitleEdit', 'Edit8'].wrapper_object().
This line should be written as either Title = app.DaVinciResolveStudioTemplate['TitleEdit', 'Edit8'].wrapper_object() or Title = app.DaVinciResolveStudioTemplate.Edit8.wrapper_object().

Visual Studio Code, Python, Alterations Not Running

I am trying to alter some code I have been given for my dissertation. However, any alterations to the modules (print statements, logging, and even trying to deliberately break the code with breaks) do not seem to affect the main program running as if those changes were not there, but changes to the main program does affect the output.
All the changes are saved and I have tried reimporting all the data files I am using and deleting all of the results before rerunning to try and start the program from "fresh". But no luck in fixing the issue.
Is there any fix to this problem? Apologies if it is an easy one, still starting out.
Main Program
eda = EDA()
cdr3_lengths = eda.get_length_of_repertoires(
repertoires=repertoires,
cdr3_col_name="aaSeqCDR3",
freq_col="cloneCount",
groups={
"01.TC8.14": "14days",
"02.TC4.14": "14days",
"03.SC8.14": "14days",
"04.SC4.14": "14days",
"05.TC8.21": "21days",
"06.TC4.21": "21days",
"07.SC8.21": "21days",
"08.SC4.21": "21days",
},
)
Module
class EDA:
# --init method etc --
def get_length_of_repertoires(
self,
repertoires: List,
groups: dict,
cdr3_col_name: str,
freq_col: str,
save_df: bool = False):
print("This isn't working")
cdr3_lengths = {}
self.logger.info("For loop fetching each repertorie.")
for repertoire in repertoires: #Repeat seqs len for count
self.logger.debug(repertoire)
.....
return 'value'
I have added some of the code that I am working with here, I believe it is being executed. I hope this helps a little more.

Some lines of code in Jupyter notebook become too slow

I always run code on Jupyter, and everything is good, but recently it takes a lot of time to execute some code, as example :
corr = train.corr()
highest_corr = corr[corr.index[abs(corr["claim"])>0.006]]
or even just :
train = pd.read_csv('Desktop\\train.csv')
So what is the problem? and how to solve it?
PS: I saw in another place that I should not use large values for :
pd.set_option('display.max_column', 120)
So I removed it, but it remains the same problem.

Runtime Error (NZEC) - Python / Codechef

I'm getting started with Codechef. I submitted following code in python to solve this question.
The code below works fine with codechef's online (python) IDE as well as my local IDE. But, when I submit it on codechef, it results in Runtime Error (NZEC). Can someone explain to me the reason behind this?
withdrawCash = int(input())
totalCash = int(input())
if withdrawCash < totalCash and withdrawCash % 5 is 0:
totalCash = (totalCash - withdrawCash) - 0.5
print(totalCash)
The problem supplies both the inputs in a single line. Your code waits for input in 2 lines. Change it to:
withdrawCash,totalCash = map(int,raw_input.split())
NZEC (Non Zero Exit Code) occurs when your code doesn't return zero on exit. It can happen due to a number of reasons, but if splitting the input doesn't solve the problem, add an exception for EOFerror. Just write:
try:
withdrawCash = int(input().split()) # raw_input in the case of Python 2
except EOFerror:
print ("exit") # this is jst a pseudo statement `
Use indentation properly. I am currently using an android app of stack exchange in which writing code is not so easy. codechef is pretty poor when it comes to Python. Switch to any other lang for CP.
Try directly submitting the code without running it on Codechef ide because it with me also it showed the same but when I submitted directly I got submitted successfully. so Directly submit your code.

Categories

Resources