From e9eef0f32b3adbd7693eff780ce09423d170ae5c Mon Sep 17 00:00:00 2001 From: Srishti Singh <47063263+srishti0908@users.noreply.github.com> Date: Thu, 24 Oct 2019 01:30:19 +0530 Subject: [PATCH 01/16] Create Overview --- list/Overview | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 list/Overview diff --git a/list/Overview b/list/Overview new file mode 100644 index 0000000..98d6cca --- /dev/null +++ b/list/Overview @@ -0,0 +1,4 @@ + Notes on List in Python + 1. Contains notes on various methods on list in python + 2. Contains the basic codes as an example + From ce3ea6da39d1a958eedac1a245eb4e333993f5e6 Mon Sep 17 00:00:00 2001 From: Srishti Singh <47063263+srishti0908@users.noreply.github.com> Date: Thu, 24 Oct 2019 01:32:09 +0530 Subject: [PATCH 02/16] Add files via upload --- list/22-lec.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 list/22-lec.py diff --git a/list/22-lec.py b/list/22-lec.py new file mode 100644 index 0000000..3e71da8 --- /dev/null +++ b/list/22-lec.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +""" +Created on Wed Jan 23 10:37:23 2019 + +@author: Dell +""" + +import random +l=[2,3,4,3,3,4,1,2,3] +random.shuffle(l) +print(l) + +random.randint(2,3) +s="hello"#firstly string is converted to lower case firstly and output is always in uppercase +s.startswith('h')#check whether starting word is h +s.endswith('O') + +s={1,2,3,3,4,5,6} +print(s) + +s="hello" +ss=set(s) +print(ss) + +ss.add(40) +ss.update(["orange"])#Always give articles in form of a list +print(ss) + + +s="hello" +ss=set(s) +print(ss) +ss.update("orange") +print(ss) + +#remove an item from set +ss.remove('h') + +ss.discard('o') + +del(ss) + +sset=set(("orange","apple")) +print(sset) \ No newline at end of file From 4feb498d884038cc8a4f12f9a3fd43c18f47bdc2 Mon Sep 17 00:00:00 2001 From: Srishti Singh <47063263+srishti0908@users.noreply.github.com> Date: Thu, 24 Oct 2019 01:32:56 +0530 Subject: [PATCH 03/16] Rename 22-lec.py to functions_on_list.py --- list/{22-lec.py => functions_on_list.py} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename list/{22-lec.py => functions_on_list.py} (91%) diff --git a/list/22-lec.py b/list/functions_on_list.py similarity index 91% rename from list/22-lec.py rename to list/functions_on_list.py index 3e71da8..91f063f 100644 --- a/list/22-lec.py +++ b/list/functions_on_list.py @@ -41,4 +41,4 @@ del(ss) sset=set(("orange","apple")) -print(sset) \ No newline at end of file +print(sset) From 7d025c07fc5e0175a19aa23e936ba78959736a3f Mon Sep 17 00:00:00 2001 From: Srishti Singh <47063263+srishti0908@users.noreply.github.com> Date: Thu, 24 Oct 2019 01:34:13 +0530 Subject: [PATCH 04/16] Add files via upload --- list/Feb 1.py | 221 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100644 list/Feb 1.py diff --git a/list/Feb 1.py b/list/Feb 1.py new file mode 100644 index 0000000..ff53c48 --- /dev/null +++ b/list/Feb 1.py @@ -0,0 +1,221 @@ +""" +Q1. WAP that will create a new list of age given the list of year of birth using list comprehension. +Q2. Create a list which will print all the characters in a string which are not vowels using list + comprehension. +Q3. Create a list of squares of numbers given a list of ten numbers using list comprehension. +Q4. WAP which will input a string from the user and gives the list of first letter of every word + in the list using list comprehension. +Q5. WAP to create a tuple containing types of fishes and using list comprehension print all the items + of the tuple if item is not octupus. +Q6. Differentiate between deep copy and shallow copy. +Q7. Write some of the features of python. +Q8. How will you get all the keys from the dictionARY.Write a small program to demonstrate it. +Q9. Do following conversions: + String to integer + String to long + String to float + String to a tupple + String to a list + String to a set + String to a dictonary +Q10.Create a dictionary using tupple. +Q11.What do you understand by frozen set. +Q12.What is the purpose of following operators:- + 1) ** + 2) // + 3) is + 4) not in +""" +#break and continue +#P1 +List_Year=[] +n=int(input("Enter number of elements in your list: ")) +for i in range(n): + x=int(input("Enter Year Of Birth: ")) + List_Year.append(x) +List_age=[2019-x for x in List_Year] +print("LIst of Ages are: ",List_age) + +#P2 +s=input("Enter a string: ") +l=[x for x in s if x not in ['a','e','i','o','u']] +print("Your list of consonants is:",l) + +#P3 +a=int(input("Enter starting number: ")) +l=[x**2 for x in range(a,a+10)] +print("Your list of square of numbers is:",l) + +#P4 +s=input("Enter any string: ") +ls=s.split() +l=[x[0] for x in ls ] +print("Your first letter of all words are:",l) + +#P5 +List=[] +n=int(input("Enter number of fishes in your list: ")) +for i in range(n): + x=input("Enter Name of Fish: ") + List.append(x) +t=tuple(List) +l=[x for x in t if x !='octopus'] +print("Your list is:",l) + + +#FEB 5/2019 +#Some more functions on lists and tupples and dictionaries. + +t=(23,45,67,78) +len(t) +max(t) #Only works when we have same datatypes ,in string compares ASCII value. +min(t) + +d1={'aman':1,'srishti':2,'babita':3} +s=str(d1) +print(s) + +#dict also has clear and copy(it makes a deep copy.) as lists. simple assignment gives (shallow copy). + +seq={'name','class','roll'} +dict1={} +dict1= dict1.fromkeys(seq,10)#wiillform keys as elements of seq and every key has a value 10 +print(dict1) +l1=[1,2,3] +dict1=dict1.fromkeys(l1)#form keys as that of l1 + +dict1={'1':1,'2':2,'3':3} + +#we can delete anything using del(list,tupple,lists). + + + +#Q1. Count the number of words in a string. +#Q2. Calculate factorial of a function using functions. + +#P1 +para=input("Enter a paragraph: ") +para.lower() +paral=para.split() +dict1={} +dict1=dict1.fromkeys(paral,0) +for p in paral: + dict1[p]=dict1[p]+1 +print(dict1) + +para=input("Enter a paragraph: ") +para.lower() +l=para.split() +d={} +for i in l: + d[i]=d.get(i,0)+1 + +#P2 +def facto(n): + if n==1: + return (1) + elif n>1: + return n*facto(n-1) + else: + print("Error!!! Negative numbers don't have a factorial") +num=int(input("Enter the number whose factorial you want to find: ")) +print("Your {number}! is: {factorial}".format(number=num,factorial=facto(num))) + + +#Create a function to check whether input is interger or not. +#Create a function to find lcm of two given number. +#Create a function which will give sum of ASCII values of all the characters in a string. +#Create a function to check whether the numbers is prime or not. + +#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +def check(i): + if i-round(i)==0 : + print("It is an interger") + else: + print("It is not an integer") +a=float(input("Input: ")) +check(a) + +def check(i): + if type(i)==type(1): + print("It is an integer") + else: + print("It is not an integer") +#--------------------------------------------------------------------------------------------------------------------- +def lcm(a,b): + z=max(a,b) + l=[] + m=[] + n=[] + for i in range(1,z+1): + if a%i==0 and b%i==0: + l.append(i) + a=a/i + b=b/i + if a%i==0 and b%i!=0: + m.append(i) + a=a/i + if a%i!=0 and b%i==0: + n.append(i) + b=b/i + print(l) + print(m) + print(n) + lm=l+m+n + print(lm) + x=1 + for i in lm: + x=x*i + return(x) +lcm(12,14) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From f7dfe32640e3a7bde222cbc7e538fbdf4269ab0b Mon Sep 17 00:00:00 2001 From: Srishti Singh <47063263+srishti0908@users.noreply.github.com> Date: Thu, 24 Oct 2019 01:35:16 +0530 Subject: [PATCH 05/16] Rename Feb 1.py to practice.py Contains some programming questions with the solution codes on lists --- list/{Feb 1.py => practice.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename list/{Feb 1.py => practice.py} (100%) diff --git a/list/Feb 1.py b/list/practice.py similarity index 100% rename from list/Feb 1.py rename to list/practice.py From 4126581228be85b58f50b63a688df0b02ffcc6f1 Mon Sep 17 00:00:00 2001 From: Srishti Singh <47063263+srishti0908@users.noreply.github.com> Date: Thu, 24 Oct 2019 01:35:49 +0530 Subject: [PATCH 06/16] Rename practice.py to practice1.py --- list/{practice.py => practice1.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename list/{practice.py => practice1.py} (100%) diff --git a/list/practice.py b/list/practice1.py similarity index 100% rename from list/practice.py rename to list/practice1.py From 1f724a59c3ad40ce68615f61f23c63f17ccff42b Mon Sep 17 00:00:00 2001 From: Srishti Singh <47063263+srishti0908@users.noreply.github.com> Date: Thu, 24 Oct 2019 01:36:10 +0530 Subject: [PATCH 07/16] Add files via upload --- list/Feb 13.py | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 list/Feb 13.py diff --git a/list/Feb 13.py b/list/Feb 13.py new file mode 100644 index 0000000..c0c9bb8 --- /dev/null +++ b/list/Feb 13.py @@ -0,0 +1,96 @@ +# -*- coding: utf-8 -*- +""" +Created on Wed Feb 13 08:59:06 2019 + +@author: Dell +""" +""" +#freelancers,fibrepay,upwork +Q1. Using L.C. ,print squares of even number from 1-20 +Q2. Using L.C. ,print the vowels present in a given string (entered by a user) +Q3. Using L.C. ,print the string in uppercase. +Q4. WAP to print a matrix. +Q5. WAP to transpose the matrix +Q6. Using L.C. ,print transpose of a matrix. +""" +#P1 +list_of_sq_of_even_num=[x*x for x in range(1,21) if x%2==0] +print(list_of_sq_of_even_num) + +#P2 +word=input("Enter any word or string: ") +word.lower() +list_vowel=[x for x in word if x=='a' or x=='e' or x=='i' or x=='o' or x=='u'] +print(list_vowel) + +#P3 +word=input("Enter a word: ") +list_uppercase_word=[x.upper() for x in word] +''.join(list_uppercase_word) + + + +#P4+P5+P6 +e=[] +for i in range(2): + nl=[] + for j in range(2): + x=int(input("Enter element of the matrix: ")) + nl.append(x) + e.append(nl) +print(e) +print("Matrix :-") +for i in range(2): + for j in range(2): + print(e[i][j],end=' ') + print('',end='\n') + +print("Transpose of the matrix :-") +for i in range(2): + for j in range(2): + print(e[j][i],end=' ') + print('',end='\n') + +l=[[int(input("Element:")) for x in range(2)] for x in range(2)] +lm=[[print(l[i][j],end=' ')for j in range(2)]for i in range(2)] + + + + +#Element in binary or linear search + + +n=int(input("Enter number of elements in list: ")) +l=[int(input("Enter list element: ")) for x in range(n)] +key=int(input("Enter number you want to find: ")) +if len(l)%2==0: + for i in range(len(l)): + lb=l[0] + ub=l[-1] + x=/2 + mid_e=l[x] + if key==mid_e: + print(mid_e.index()) + elif key>mid_e: + l=l[x+1:] + else: + l=l[:x-1] +else: + for i in range(len(l)+1): + x=(len(l)-1) + y=x/2 + mid_e=l[y] + if key==mid_e: + print(mid_e.index()) + elif key>mid_e: + lb=mid_e+1 + else: + ub=mid_e-1 + + + + + + + + \ No newline at end of file From 165a0b763125a605b4d2f26c5143c8759725d0f3 Mon Sep 17 00:00:00 2001 From: Srishti Singh <47063263+srishti0908@users.noreply.github.com> Date: Thu, 24 Oct 2019 01:37:19 +0530 Subject: [PATCH 08/16] Rename Feb 13.py to practice2.py Questions with solution codes on list and more topics --- list/{Feb 13.py => practice2.py} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename list/{Feb 13.py => practice2.py} (95%) diff --git a/list/Feb 13.py b/list/practice2.py similarity index 95% rename from list/Feb 13.py rename to list/practice2.py index c0c9bb8..c2bf2d2 100644 --- a/list/Feb 13.py +++ b/list/practice2.py @@ -93,4 +93,4 @@ - \ No newline at end of file + From ef06121c8a9551256da36c3f9decb76fadde6a6d Mon Sep 17 00:00:00 2001 From: Srishti Singh <47063263+srishti0908@users.noreply.github.com> Date: Thu, 24 Oct 2019 01:38:39 +0530 Subject: [PATCH 09/16] Add files via upload Explains various commands on list in python with examples and code --- list/commands on list.py | 136 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 list/commands on list.py diff --git a/list/commands on list.py b/list/commands on list.py new file mode 100644 index 0000000..1ac15ef --- /dev/null +++ b/list/commands on list.py @@ -0,0 +1,136 @@ +""" CLEAR COMMAND """ +l=[1,2,3,4,5,6] +l.clear() +#Use to clear all elements in the list +# but maintain the id of the objects (erased elements of the list). +print(l) + + + +""" COPY COMMAND """ +l=[1,2] +l1=l +#so here actually whats happening a copy of l is not made in l1 +#instead l1 will also call the same elements as being called by l. +id(l) +# in python whatever is in square brackets in a list are objects. +id(l1) +#Hence, both the id of l and l1 will be same +#no copy of the list is made. + +#so lets do try append 'l1' and see if it affects 'l' or not + +l1.append(4) +print(l1)# l1 got changed +print(l)# so did l + +"""But what if i don't want to change l and +make l1 a copy of the objects not the pointer of the same objects. +We have a command called copy() in lists """ + +#Let's use the copy command. +l=[1,2] +l1=l.copy()#makes a copy of object at different ID +print(id(l)) +print(id(l1)) +l1.append(4)# Will only change l1 not l. +print(l) +print(l1) + + +""" AN ANALOGY OF THE COPY COMMAND """ +""" without copy command """ +#Suppose you want to read a novel. +#You asked one of your friends(Srishti) for it. +#She found it in the library and told u it's location +#(same like variable gives you a output via print command) +#You asked another friend(Prashant) too. +#He contacted Srishti and told u about the same location. + + +""" with copy command """ +#Suppose you want to read a novel. +#You asked one of your friends(Srishti) for it. +#She found it in the library and told u it's location +#(same like variable gives you a output via print command) +#You asked another friend(Prashant) too. +#He contacted Srishti and went to the library +#Took a copy of it and added it to his own personal llibrary +#Now told you to come and read it from his library whenever u want to. + + +l=[1,2,3,4,5,6] +le=[] +for i in l: + if i%2==0: + le.append(i) + +lee=[i for i in l if i%2==0] + +lx=[x**2 for x in l] + +import keyword +keyword.iskeyword("1srishti")#willl tell us whether the word is a keyword or not + +'1srish'.isidentifier()#helps in identifying whether the name given to any identifier +# is feasible or not but it can't differentiate the keywords + + + +#program to find feasible names of an identifier +#By:-Srishti Singh +c=input("Enter any string: ") +import keyword +if(keyword.iskeyword(c)==False and c.isidentifier()==True ): + print("It is an identifier") +else: + print("It is not an identifier") + + +l=[1,2,3,[4,5],6,7,8] +import copy +a=copy.copy(l) +b=copy.deepcopy(l) +print(a,b) +l[3][0]=10 +print(a,b) + + +#Program to show difference between shallow and deep copy +l=[1,2,3,[4,5],6,7,8] +import copy +a=copy.copy(l) +b=copy.deepcopy(l) +print("Original list:",l) +print("Your Shallow Copied list is:",a) +print("Your Deep Copied list is:",b) +l[3][0]=10 +print("Original list after alteration:",l) +print("Shallow Copied list after alteration:",a) +print("Deep Copied list after alteration:",b) + +d={"Name":"Srishti Singh","System ID":2018013720,"Course":"B.Tech. CSE with specialisation in A.I. and Machine Learning"} +a=d.keys() +print(a) + +s="234" +integer_s=int(s) +float_s=float(s) +tuple_s=tuple(s) +list_s=list(s) + + + + + + + + + + + + + + + + From b30a0ee1c483a2cc176cb05e2f635a60d4ea4723 Mon Sep 17 00:00:00 2001 From: Srishti Singh <47063263+srishti0908@users.noreply.github.com> Date: Thu, 24 Oct 2019 01:40:16 +0530 Subject: [PATCH 10/16] Add files via upload Code to make a separate lists of even and odd numbers from a single list of numbers --- list/evenodd.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 list/evenodd.py diff --git a/list/evenodd.py b/list/evenodd.py new file mode 100644 index 0000000..b941e1e --- /dev/null +++ b/list/evenodd.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +""" +Created on Wed Jan 16 10:07:18 2019 + +@author: Dell +""" + +#to sort even odd numbers +l=[] +s=int(input("Enter Number of Elements in the List: ")) +for i in range(s): + x=int(input("Enter element in the list: ")) + l.append(x) +e=[] +o=[] +for i in range(len(l)): + if l[i]%2==0: + e.append(l[i]) + else: + o.append(l[i]) +print("List of your Even Numbers is:",e) +print("List of your Odd Numbers is:",o) + + + + + From 9d825da8c0bc5000f68e0ef387365d97b9f09bd6 Mon Sep 17 00:00:00 2001 From: Srishti Singh <47063263+srishti0908@users.noreply.github.com> Date: Thu, 24 Oct 2019 01:41:20 +0530 Subject: [PATCH 11/16] Add files via upload --- list/lab 3.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 list/lab 3.py diff --git a/list/lab 3.py b/list/lab 3.py new file mode 100644 index 0000000..9663633 --- /dev/null +++ b/list/lab 3.py @@ -0,0 +1,57 @@ +# 1. WAP to create and merge two list and then sort it wihtout function sort +# 2. WAP to create list of number and sort even numbers using LIST COMPREHENSION +# 3. WAP to calculate number of uppercase and lowercase from input string. + +l1=[] +l2=[] +a=int(input("Enter number of elements you want to enter in list 1: ")) +b=int(input("Enter number of elements you want to enter in list 2: ")) + +for i in range(a): + x=int(input("Enter List Element: ")) + l1.append(x) + +for i in range(b): + x=int(input("Enter List Element: ")) + l2.append(x) + +l1.extend(l2) +m=[] +for i in range (len(l1)): + m.append(min(l1)) + l1.remove(min(l1)) +m.extend(l1) +print(m,end=" ") +print("is your sorted list") + +#P2 + +l=[] +a=int(input("Number of elements in the list: ")) + +for i in range(a): + x=int(input("Enter List Element: ")) + l.append(x) + +lee=[i for i in l if i%2==0] +print("List of your even numbers is={evenlist}".format(evenlist=lee)) + +#P3 + +s=input("Enter any word string: ") +cu=0 +cl=0 +for i in s: + if i.isupper(): + cu=cu+1 + else: + cl=cl+1 +print("Number of lower case:",cl) +print("Number of upper case:",cu) + + + + + + + From d6ab38da928e1948f45f7043fe2ceb2148479ad4 Mon Sep 17 00:00:00 2001 From: Srishti Singh <47063263+srishti0908@users.noreply.github.com> Date: Thu, 24 Oct 2019 01:41:48 +0530 Subject: [PATCH 12/16] Rename lab 3.py to practice3.py --- list/{lab 3.py => practice3.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename list/{lab 3.py => practice3.py} (100%) diff --git a/list/lab 3.py b/list/practice3.py similarity index 100% rename from list/lab 3.py rename to list/practice3.py From 7a9791a6eaf3e11f0df7587a00b3bb0beac5a68c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Dec 2019 00:50:56 +0000 Subject: [PATCH 13/16] build(deps): bump ecdsa from 0.13 to 0.13.3 in /flask/flaskr-tdd Bumps [ecdsa](https://github.com/warner/python-ecdsa) from 0.13 to 0.13.3. - [Release notes](https://github.com/warner/python-ecdsa/releases) - [Changelog](https://github.com/warner/python-ecdsa/blob/master/NEWS) - [Commits](https://github.com/warner/python-ecdsa/compare/python-ecdsa-0.13...python-ecdsa-0.13.3) Signed-off-by: dependabot[bot] --- flask/flaskr-tdd/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flask/flaskr-tdd/requirements.txt b/flask/flaskr-tdd/requirements.txt index 0366ea1..a858efe 100644 --- a/flask/flaskr-tdd/requirements.txt +++ b/flask/flaskr-tdd/requirements.txt @@ -1,6 +1,6 @@ coverage==4.0 docopt==0.6.2 -ecdsa==0.13 +ecdsa==0.13.3 Fabric==1.10.2 Flask==0.10.1 Flask-Boost==0.7.2 From e1b7ca0a3b1b229a5155e4d7a0900dde4ec13fc6 Mon Sep 17 00:00:00 2001 From: dineshkumar2509 <54076851+dineshkumar2509@users.noreply.github.com> Date: Fri, 2 Oct 2020 13:32:22 +0530 Subject: [PATCH 14/16] Update args.py --- func/args.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/func/args.py b/func/args.py index 0299aaf..fb38377 100644 --- a/func/args.py +++ b/func/args.py @@ -11,9 +11,9 @@ def x(a, b, *c): # 参数前面为**, 代表这个位置的参数不知道有多少个参数, 如果有, 则将其存储为字典 def y(*c, **k): - print c - print k + print(c) + print(k) if __name__ == "__main__": x(1,2,3,4) - y(1,2,a="b",c="d") \ No newline at end of file + y(1,2,a="b",c="d") From 08611d830be696832a5d12de9471849a6fe9ef11 Mon Sep 17 00:00:00 2001 From: Akagi201 Date: Tue, 29 Aug 2023 21:45:47 +0800 Subject: [PATCH 15/16] feat: add asyncio --- asyncio/ccxt_async.py | 34 ++++++++++++++++++++++++++++++++++ asyncio/multi_tasks.py | 16 ++++++++++++++++ asyncio/simple.py | 8 ++++++++ 3 files changed, 58 insertions(+) create mode 100644 asyncio/ccxt_async.py create mode 100644 asyncio/multi_tasks.py create mode 100644 asyncio/simple.py diff --git a/asyncio/ccxt_async.py b/asyncio/ccxt_async.py new file mode 100644 index 0000000..d217141 --- /dev/null +++ b/asyncio/ccxt_async.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- + +import asyncio +import functools +import os +import sys + +root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +sys.path.append(root + '/python') + +import ccxt.async_support as ccxt # noqa: E402 + + +async def print_ticker(symbol, id): + # verbose mode will show the order of execution to verify concurrency + exchange = getattr(ccxt, id)({'verbose': True}) + print(await exchange.fetch_ticker(symbol)) + await exchange.close() + + +if __name__ == '__main__': + + symbol = 'ETH/BTC' + print_ethbtc_ticker = functools.partial(print_ticker, symbol) + [asyncio.ensure_future(print_ethbtc_ticker(id)) for id in [ + 'bitfinex', + 'poloniex', + 'kraken', + 'bittrex', + 'hitbtc', + ]] + loop = asyncio.get_event_loop() + pending = asyncio.all_tasks(loop) + loop.run_until_complete(asyncio.gather(*pending)) \ No newline at end of file diff --git a/asyncio/multi_tasks.py b/asyncio/multi_tasks.py new file mode 100644 index 0000000..ee081f1 --- /dev/null +++ b/asyncio/multi_tasks.py @@ -0,0 +1,16 @@ +import asyncio +import time + +async def say_after(delay, what): + await asyncio.sleep(delay) + print(what) + +async def main(): + print(f"started at {time.strftime('%X')}") + + await say_after(1, 'hello') + await say_after(2, 'world') + + print(f"finished at {time.strftime('%X')}") + +asyncio.run(main()) diff --git a/asyncio/simple.py b/asyncio/simple.py new file mode 100644 index 0000000..675b564 --- /dev/null +++ b/asyncio/simple.py @@ -0,0 +1,8 @@ +import asyncio + +async def main(): + print('Hello ...') + await asyncio.sleep(1) + print('... World!') + +asyncio.run(main()) From 5e019662040800e8997002d31588534093b79a43 Mon Sep 17 00:00:00 2001 From: Akagi201 Date: Thu, 16 May 2024 14:10:43 +0800 Subject: [PATCH 16/16] chore: delete file --- .../test_matplot-checkpoint.ipynb | 107 ------------------ 1 file changed, 107 deletions(-) delete mode 100644 ipython/.ipynb_checkpoints/test_matplot-checkpoint.ipynb diff --git a/ipython/.ipynb_checkpoints/test_matplot-checkpoint.ipynb b/ipython/.ipynb_checkpoints/test_matplot-checkpoint.ipynb deleted file mode 100644 index 5cb5fe5..0000000 --- a/ipython/.ipynb_checkpoints/test_matplot-checkpoint.ipynb +++ /dev/null @@ -1,107 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 4, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from matplotlib.pyplot import *\n", - "from numpy import *\n", - "x = linspace(0, 2 * pi)\n", - "plot(x, sin(x), label=r'$\\sin(x)$')\n", - "plot(x, cos(x), 'ro', label=r'$\\cos(x)$')\n", - "title(r'Two familiar functions')\n", - "legend()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 2", - "language": "python", - "name": "python2" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 2 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.9" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -}