My code for Tic-Tac-Toe (beginner), compared to my mate that works at google's code.
Thought it would be interesting seeing someone beginner code, vs someone's professional code on the same project. After I sent him my code he replied with how he would have done it, as a comparison.
**My code:**
import random
def plyr1wintest(): #checks if player has 3 in a row
global winner
if (1 in plyr1list) and (2 in plyr1list) and (3 in plyr1list) or \
(4 in plyr1list) and (5 in plyr1list) and (6 in plyr1list) or \
(7 in plyr1list) and (8 in plyr1list) and (9 in plyr1list) or \
(1 in plyr1list) and (4 in plyr1list) and (7 in plyr1list) or \
(2 in plyr1list) and (5 in plyr1list) and (8 in plyr1list) or \
(3 in plyr1list) and (6 in plyr1list) and (9 in plyr1list) or \
(1 in plyr1list) and (5 in plyr1list) and (9 in plyr1list) or \
(3 in plyr1list) and (5 in plyr1list) and (7 in plyr1list):
print ((name1) + ' wins as X')
winner = True
def plyr2wintest(): #checks if player has three in a row
global winner
if (1 in plyr2list) and (2 in plyr2list) and (3 in plyr2list) or \
(4 in plyr2list) and (5 in plyr2list) and (6 in plyr2list) or \
(7 in plyr2list) and (8 in plyr2list) and (9 in plyr2list) or \
(1 in plyr2list) and (4 in plyr2list) and (7 in plyr2list) or \
(2 in plyr2list) and (5 in plyr2list) and (8 in plyr2list) or \
(3 in plyr2list) and (6 in plyr2list) and (9 in plyr2list) or \
(1 in plyr2list) and (5 in plyr2list) and (9 in plyr2list) or \
(3 in plyr2list) and (5 in plyr2list) and (7 in plyr2list):
print ((name2) + ' wins as O')
winner = True
def printboard(): #print board
print(' ')
print(' '+ position[0] +' | '+ position[1] +' | '+ position[2] + ' ' + ' '+ '1' +' | '+ '2' +' | '+ '3')
print('-----------' + ' ' + '-----------')
print(' '+ position[3] +' | '+ position[4] +' | '+ position[5] + ' ' + ' '+ '4' +' | '+ '5' +' | '+ '6')
print('-----------' + ' ' + '-----------')
print(' '+ position[6] +' | '+ position[7] +' | '+ position[8] + ' ' + ' '+ '7' +' | '+ '8' +' | '+ '9')
print(' ')
winner = False #win checker
movecount = 0 #counts amount of turns
playgame = True
print ('welcome to Noughts & Crosses') #title
while playgame == True:
position = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '] #sets the board spaces blank
plyr1list = []
plyr2list = []
gamelist = []
winner = False
movecount = 0
print (' ')
#Name input
print ('What is player 1s name?')
name1 = input()
print ('thanks '+ (name1) +', Whats player 2s name?')
name2 = input()
print ('so '+ (name1) +' is X and '+ (name2) + ' is O')
input("Press Enter to continue...")
printboard()
while (movecount < 9) and (winner == False):
if (movecount % 2 == 0): #player 1 turn
print ((name1) + 's ( X ) turn, please choose placement (1-9)')
move = input()
if move in ('1', '2', '3', '4', '5', '6', '7', '8', '9') and (int(move) not in (gamelist)):
plyr1list.append(int(move))
gamelist.append(int(move))
print (gamelist) #debug
position[int(move)-1] = ('X')
printboard()
movecount = movecount + 1
plyr1wintest()
elif move not in ('1', '2', '3', '4', '5', '6', '7', '8', '9'):
print ('That is not a valid move! Try again')
else: print ('That move is taken!, Try again')
else: #player 2 turn
print ((name2) + 's ( O ) turn, please choose placement (1-9)')
Thought it would be interesting seeing someone beginner code, vs someone's professional code on the same project. After I sent him my code he replied with how he would have done it, as a comparison.
**My code:**
import random
def plyr1wintest(): #checks if player has 3 in a row
global winner
if (1 in plyr1list) and (2 in plyr1list) and (3 in plyr1list) or \
(4 in plyr1list) and (5 in plyr1list) and (6 in plyr1list) or \
(7 in plyr1list) and (8 in plyr1list) and (9 in plyr1list) or \
(1 in plyr1list) and (4 in plyr1list) and (7 in plyr1list) or \
(2 in plyr1list) and (5 in plyr1list) and (8 in plyr1list) or \
(3 in plyr1list) and (6 in plyr1list) and (9 in plyr1list) or \
(1 in plyr1list) and (5 in plyr1list) and (9 in plyr1list) or \
(3 in plyr1list) and (5 in plyr1list) and (7 in plyr1list):
print ((name1) + ' wins as X')
winner = True
def plyr2wintest(): #checks if player has three in a row
global winner
if (1 in plyr2list) and (2 in plyr2list) and (3 in plyr2list) or \
(4 in plyr2list) and (5 in plyr2list) and (6 in plyr2list) or \
(7 in plyr2list) and (8 in plyr2list) and (9 in plyr2list) or \
(1 in plyr2list) and (4 in plyr2list) and (7 in plyr2list) or \
(2 in plyr2list) and (5 in plyr2list) and (8 in plyr2list) or \
(3 in plyr2list) and (6 in plyr2list) and (9 in plyr2list) or \
(1 in plyr2list) and (5 in plyr2list) and (9 in plyr2list) or \
(3 in plyr2list) and (5 in plyr2list) and (7 in plyr2list):
print ((name2) + ' wins as O')
winner = True
def printboard(): #print board
print(' ')
print(' '+ position[0] +' | '+ position[1] +' | '+ position[2] + ' ' + ' '+ '1' +' | '+ '2' +' | '+ '3')
print('-----------' + ' ' + '-----------')
print(' '+ position[3] +' | '+ position[4] +' | '+ position[5] + ' ' + ' '+ '4' +' | '+ '5' +' | '+ '6')
print('-----------' + ' ' + '-----------')
print(' '+ position[6] +' | '+ position[7] +' | '+ position[8] + ' ' + ' '+ '7' +' | '+ '8' +' | '+ '9')
print(' ')
winner = False #win checker
movecount = 0 #counts amount of turns
playgame = True
print ('welcome to Noughts & Crosses') #title
while playgame == True:
position = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '] #sets the board spaces blank
plyr1list = []
plyr2list = []
gamelist = []
winner = False
movecount = 0
print (' ')
#Name input
print ('What is player 1s name?')
name1 = input()
print ('thanks '+ (name1) +', Whats player 2s name?')
name2 = input()
print ('so '+ (name1) +' is X and '+ (name2) + ' is O')
input("Press Enter to continue...")
printboard()
while (movecount < 9) and (winner == False):
if (movecount % 2 == 0): #player 1 turn
print ((name1) + 's ( X ) turn, please choose placement (1-9)')
move = input()
if move in ('1', '2', '3', '4', '5', '6', '7', '8', '9') and (int(move) not in (gamelist)):
plyr1list.append(int(move))
gamelist.append(int(move))
print (gamelist) #debug
position[int(move)-1] = ('X')
printboard()
movecount = movecount + 1
plyr1wintest()
elif move not in ('1', '2', '3', '4', '5', '6', '7', '8', '9'):
print ('That is not a valid move! Try again')
else: print ('That move is taken!, Try again')
else: #player 2 turn
print ((name2) + 's ( O ) turn, please choose placement (1-9)')
move = input()
if move in ('1', '2', '3', '4', '5', '6', '7', '8', '9') and (int(move) not in (gamelist)):
plyr2list.append(int(move))
gamelist.append(int(move))
print (gamelist) #debug
position[int(move)-1] = ('O')
printboard()
movecount = movecount + 1
plyr2wintest()
elif move not in ('1', '2', '3', '4', '5', '6', '7', '8', '9'):
print ('That is not a valid move! Try again')
else: print ('That move is taken!, Try again')
#end game
if winner == True:
print ('Congrats!')
else: print ('Its a tie BOI!')
print (' ')
#playagain
answer = 0
valid = False
print ('Would you like to play again (y/n)')
while valid == False: #waits until valid answer is submitted
answer = input()
if answer == 'y':
print ('aight, resetting...')
valid = True
elif answer == 'n':
print ('aight, cya')
print (' ') #ASCII art up in here cause why not
print(' * ,MMM8&&&. *')
print(' MMMM88&&&&& .')
print(' MMMM88&&&&&&&')
print(' * MMM88&&&&&&&&')
print(' MMM88&&&&&&&&')
print(' MMM88&&&&&&')
print(' MMM8&&& *')
print(' |\___/| ')
print(' ) ( . ')
print(' =\ /=')
print(' )===( Thanks for playing *')
print(' / \ ')
print(' | |')
print(' / \ ')
print(' \ / ')
print(' _/\_/\_/\__ _/_/\_/\_/\_/\_/\_/\_/\_/\_/\_ ')
print(' | | | |( ( | | | | | | | | | | ')
print(' | | | | ) ) | | | | | | | | | | ')
print(' | | | |(_( | | | | | | | | | | ')
print(' | | | | | | | | | | | | | | | ')
print(' By Me yay| | | | | | | | | ')
valid = True
playgame = False
else: print ('answer not valid, please use y or n')
#End
**His code:**
#!/usr/bin/python
"""Noughts and Crosses."""
import sys
def Input(*args):
"""Kludge to handle python 2 and 3."""
if sys.version_info.major >= 3:
return input(*args)
return raw_input(*args)
bye = r"""
* ,MMM8&&&. *
MMMM88&&&&& .
MMMM88&&&&&&&
* MMM88&&&&&&&&
MMM88&&&&&&&&
MMM88&&&&&&
MMM8&&& *
|\___/|
) ( .
=\ /=
)===( Thanks for playing *
/ \
| |
/ \
\ /
_/\_/\_/\__ _/_/\_/\_/\_/\_/\_/\_/\_/\_/\_
| | | |( ( | | | | | | | | | |
| | | | ) ) | | | | | | | | | |
| | | |(_( | | | | | | | | | |
| | | | | | | | | | | | | | |
By Me yay | | | | | | | | |
"""
def Play():
"""Play one round of noughts and crosses."""
position = [' ' for _ in range(9)]
print ("What is player 1's name?")
name1 = Input()
print ("Thanks %s, What's player 2's name?" % name1)
name2 = Input()
print ('So %s is X and %s is O.' % (name1, name2))
Input('Press Enter to continue...')
PrintBoard(position)
players = [(name1, 'X'), (name2, 'O')]
if move in ('1', '2', '3', '4', '5', '6', '7', '8', '9') and (int(move) not in (gamelist)):
plyr2list.append(int(move))
gamelist.append(int(move))
print (gamelist) #debug
position[int(move)-1] = ('O')
printboard()
movecount = movecount + 1
plyr2wintest()
elif move not in ('1', '2', '3', '4', '5', '6', '7', '8', '9'):
print ('That is not a valid move! Try again')
else: print ('That move is taken!, Try again')
#end game
if winner == True:
print ('Congrats!')
else: print ('Its a tie BOI!')
print (' ')
#playagain
answer = 0
valid = False
print ('Would you like to play again (y/n)')
while valid == False: #waits until valid answer is submitted
answer = input()
if answer == 'y':
print ('aight, resetting...')
valid = True
elif answer == 'n':
print ('aight, cya')
print (' ') #ASCII art up in here cause why not
print(' * ,MMM8&&&. *')
print(' MMMM88&&&&& .')
print(' MMMM88&&&&&&&')
print(' * MMM88&&&&&&&&')
print(' MMM88&&&&&&&&')
print(' MMM88&&&&&&')
print(' MMM8&&& *')
print(' |\___/| ')
print(' ) ( . ')
print(' =\ /=')
print(' )===( Thanks for playing *')
print(' / \ ')
print(' | |')
print(' / \ ')
print(' \ / ')
print(' _/\_/\_/\__ _/_/\_/\_/\_/\_/\_/\_/\_/\_/\_ ')
print(' | | | |( ( | | | | | | | | | | ')
print(' | | | | ) ) | | | | | | | | | | ')
print(' | | | |(_( | | | | | | | | | | ')
print(' | | | | | | | | | | | | | | | ')
print(' By Me yay| | | | | | | | | ')
valid = True
playgame = False
else: print ('answer not valid, please use y or n')
#End
**His code:**
#!/usr/bin/python
"""Noughts and Crosses."""
import sys
def Input(*args):
"""Kludge to handle python 2 and 3."""
if sys.version_info.major >= 3:
return input(*args)
return raw_input(*args)
bye = r"""
* ,MMM8&&&. *
MMMM88&&&&& .
MMMM88&&&&&&&
* MMM88&&&&&&&&
MMM88&&&&&&&&
MMM88&&&&&&
MMM8&&& *
|\___/|
) ( .
=\ /=
)===( Thanks for playing *
/ \
| |
/ \
\ /
_/\_/\_/\__ _/_/\_/\_/\_/\_/\_/\_/\_/\_/\_
| | | |( ( | | | | | | | | | |
| | | | ) ) | | | | | | | | | |
| | | |(_( | | | | | | | | | |
| | | | | | | | | | | | | | |
By Me yay | | | | | | | | |
"""
def Play():
"""Play one round of noughts and crosses."""
position = [' ' for _ in range(9)]
print ("What is player 1's name?")
name1 = Input()
print ("Thanks %s, What's player 2's name?" % name1)
name2 = Input()
print ('So %s is X and %s is O.' % (name1, name2))
Input('Press Enter to continue...')
PrintBoard(position)
players = [(name1, 'X'), (name2, 'O')]
for movecount in range(9):
player = players[movecount % 2]
while True:
print ("%s's ( %s ) turn, please choose placement [1-9]?" % player)
try:
move = int(Input())
except ValueError:
print ('Invalid input, please choose placement [1-9]?')
continue
if move < 1 or move > 9:
print ('That is not a valid move! Try again.')
continue
if position[move-1] != ' ':
print ('That move is taken!, Try again.')
continue
break
position[move-1] = player[1]
PrintBoard(position)
if PlayerWin(position, player):
print ('%s wins as %s.' % player)
break
else:
print ('Its a tie BOI!')
def PrintBoard(position):
print ("""
%s | %s | %s 1 | 2 | 3
----------- -----------
%s | %s | %s 4 | 5 | 6
----------- -----------
%s | %s | %s 7 | 8 | 9
""" % tuple(p for p in position))
def PlayerWin(position, player):
def Marks(m1, m2, m3):
return tuple(position[i-1] for i in (m1, m2, m3))
mark = player[1]
win = (mark, mark, mark)
return (
Marks(4, 5, 6) == win or
Marks(7, 8, 9) == win or
Marks(1, 4, 7) == win or
Marks(2, 5, 8) == win or
Marks(3, 6, 9) == win or
Marks(1, 5, 9) == win or
Marks(3, 5, 7) == win
)
# Now let's get down to business.
print ('Welcome to Noughts & Crosses.')
while True:
Play()
while True:
print ('Would you like to play again (y/n)?')
answer = Input()
if answer in ('y', 'n'):
break
if answer == 'n':
break
print ('Aight, resetting...')
print ('Aight, cya.')
print (bye)
/r/Python
https://redd.it/6qvu38
player = players[movecount % 2]
while True:
print ("%s's ( %s ) turn, please choose placement [1-9]?" % player)
try:
move = int(Input())
except ValueError:
print ('Invalid input, please choose placement [1-9]?')
continue
if move < 1 or move > 9:
print ('That is not a valid move! Try again.')
continue
if position[move-1] != ' ':
print ('That move is taken!, Try again.')
continue
break
position[move-1] = player[1]
PrintBoard(position)
if PlayerWin(position, player):
print ('%s wins as %s.' % player)
break
else:
print ('Its a tie BOI!')
def PrintBoard(position):
print ("""
%s | %s | %s 1 | 2 | 3
----------- -----------
%s | %s | %s 4 | 5 | 6
----------- -----------
%s | %s | %s 7 | 8 | 9
""" % tuple(p for p in position))
def PlayerWin(position, player):
def Marks(m1, m2, m3):
return tuple(position[i-1] for i in (m1, m2, m3))
mark = player[1]
win = (mark, mark, mark)
return (
Marks(4, 5, 6) == win or
Marks(7, 8, 9) == win or
Marks(1, 4, 7) == win or
Marks(2, 5, 8) == win or
Marks(3, 6, 9) == win or
Marks(1, 5, 9) == win or
Marks(3, 5, 7) == win
)
# Now let's get down to business.
print ('Welcome to Noughts & Crosses.')
while True:
Play()
while True:
print ('Would you like to play again (y/n)?')
answer = Input()
if answer in ('y', 'n'):
break
if answer == 'n':
break
print ('Aight, resetting...')
print ('Aight, cya.')
print (bye)
/r/Python
https://redd.it/6qvu38
reddit
My code for Tic-Tac-Toe (beginner), compared to my mate... • r/Python
Thought it would be interesting seeing someone beginner code, vs someone's professional code on the same project. After I sent him my code he...
Sinuous Violin (elementary sound spectral analysis and synthesis with Python)
https://mapio.github.io/sinuous-violin/
/r/JupyterNotebooks
https://redd.it/6qzmbf
https://mapio.github.io/sinuous-violin/
/r/JupyterNotebooks
https://redd.it/6qzmbf
reddit
Sinuous Violin (elementary sound spectral... • r/JupyterNotebooks
1 points and 0 comments so far on reddit
PySwarms - A particle swarm optimization (PSO) library in Python
https://github.com/ljvmiranda921/pyswarms
/r/Python
https://redd.it/6r26ug
https://github.com/ljvmiranda921/pyswarms
/r/Python
https://redd.it/6r26ug
GitHub
GitHub - ljvmiranda921/pyswarms: A research toolkit for particle swarm optimization in Python
A research toolkit for particle swarm optimization in Python - GitHub - ljvmiranda921/pyswarms: A research toolkit for particle swarm optimization in Python
How to use chromeless with Python?
Hello,
I wonder if there is any way to use this chromeless with Python?
https://github.com/graphcool/chromeless
It looks like a great tool but unfortunately i do not know if there is any way to use it with python.
Thank you
/r/Python
https://redd.it/6r2lsd
Hello,
I wonder if there is any way to use this chromeless with Python?
https://github.com/graphcool/chromeless
It looks like a great tool but unfortunately i do not know if there is any way to use it with python.
Thank you
/r/Python
https://redd.it/6r2lsd
GitHub
GitHub - schickling/chromeless: 🖥 Chrome automation made simple. Runs locally or headless on AWS Lambda.
🖥 Chrome automation made simple. Runs locally or headless on AWS Lambda. - schickling/chromeless
Which platform to quickly build a (paid) python-based API
Hi!
I have a python algorithm and I want to make a scalable web interface / API for that algorithm.
**First I would like to enable people to make call to my algorithm, either on the web interface or through a web api.**
- Which platform would be the best for me ? AWS lambda ? google app engine ? pythonanywhere ? something else ?
**Then if it works well I would like to create billing plans such as "ipinfo.io" (like 20 euros per month for X calls / X CPU time used...)**
- I know how to code in python / php but I don't see myself building the whole used authentification / billing plans.. payment tracking. Is there an easy platform to set up paid apis ?
Finally.. i'm poor so I can't afford to spend too much. I've seen 3scale for example but 750 euros is too much, especially considering that my algorithm is quite simple (like just a function with some arguments processed by a single python function, which gives back one or multiple numbers..).
Thanks!
/r/Python
https://redd.it/6r2r88
Hi!
I have a python algorithm and I want to make a scalable web interface / API for that algorithm.
**First I would like to enable people to make call to my algorithm, either on the web interface or through a web api.**
- Which platform would be the best for me ? AWS lambda ? google app engine ? pythonanywhere ? something else ?
**Then if it works well I would like to create billing plans such as "ipinfo.io" (like 20 euros per month for X calls / X CPU time used...)**
- I know how to code in python / php but I don't see myself building the whole used authentification / billing plans.. payment tracking. Is there an easy platform to set up paid apis ?
Finally.. i'm poor so I can't afford to spend too much. I've seen 3scale for example but 750 euros is too much, especially considering that my algorithm is quite simple (like just a function with some arguments processed by a single python function, which gives back one or multiple numbers..).
Thanks!
/r/Python
https://redd.it/6r2r88
reddit
Which platform to quickly build a (paid) python-based API • r/Python
Hi! I have a python algorithm and I want to make a scalable web interface / API for that algorithm. **First I would like to enable people to...
Django app that returns value based on what users choose in form (x-post r/django)
I did the tutorial on the Django website and made the polls app. I've since added static pages and gained a better understanding of how URLs and views work.
I've written a Python function that is essentially a logistic regression predictor. It takes in an array and based on that array returns a value.
I want to build off the polls app in Django, and make it so that instead of typing in an array, users can select from the poll form, and then the web app returns the value.
How would I go about starting this?
/r/djangolearning
https://redd.it/6r0q9e
I did the tutorial on the Django website and made the polls app. I've since added static pages and gained a better understanding of how URLs and views work.
I've written a Python function that is essentially a logistic regression predictor. It takes in an array and based on that array returns a value.
I want to build off the polls app in Django, and make it so that instead of typing in an array, users can select from the poll form, and then the web app returns the value.
How would I go about starting this?
/r/djangolearning
https://redd.it/6r0q9e
reddit
Django app that returns value based on what... • r/djangolearning
I did the tutorial on the Django website and made the polls app. I've since added static pages and gained a better understanding of how URLs and...
Is this no longer the place to post notifications about Python library updates?
Lately, when I post notices about a new release of one of my Python libraries here, the post is pretty reliably downvoted. If people really don't care about the libraries I'm putting out, that's fine, but I just wanted to make sure I'm not violating a rule of some kind.
/r/Python
https://redd.it/6r3sbk
Lately, when I post notices about a new release of one of my Python libraries here, the post is pretty reliably downvoted. If people really don't care about the libraries I'm putting out, that's fine, but I just wanted to make sure I'm not violating a rule of some kind.
/r/Python
https://redd.it/6r3sbk
reddit
Is this no longer the place to post notifications about... • r/Python
Lately, when I post notices about a new release of one of my Python libraries here, the post is pretty reliably downvoted. If people really don't...
[P] Detecting the bats outside of my appartment by recognising their sound with Tensorflow
https://medium.com/@rmeertens/detecting-bats-by-recognising-their-sound-with-tensorflow-cdd5e1c22b14
/r/MachineLearning
https://redd.it/6r3kzd
https://medium.com/@rmeertens/detecting-bats-by-recognising-their-sound-with-tensorflow-cdd5e1c22b14
/r/MachineLearning
https://redd.it/6r3kzd
Medium
Detecting bats by recognising their sound with Tensorflow
Last week I discovered that there are bats behind my appartment. I immediately grabbed my “bat detector”: a device that converts the ultrasound signals bats use to echolocate from an inaudible…
[HELP] Left Join between multiple databases
I want to do a left join with another db, What would be the django equivalent of this query ?
USE PARTNER_DB;
SELECT CLIENT_ID, PARTNER.FIRST_NAME, PARTNER.LAST_NAME,
RPM, DRAWDOWN_PROTECTION, CONCAT(EMPLOYEE_DB.EMPLOYEE.FIRST_NAME, " ", EMPLOYEE_DB.EMPLOYEE.LAST_NAME),
EMPLOYEE_DB.EMPLOYEE.MAIL
FROM PARTNER
LEFT JOIN EMPLOYEE_DB.EMPLOYEE
ON RM_ID = EMPLOYEE_DB.EMPLOYEE.EMP_ID
WHERE CLIENT_ID = 'X1234'
I am using multiple databases in my project and both of these databases are not managed by django.
I tried to dig into django documentation but was unable to find a way to achieve this, instead i bumped into this
[https://docs.djangoproject.com/en/1.11/topics/db/multi-db/#no-cross-database-relations][1].
I am sure that there will be a hack / workaround this. Looking forward to your solutions.
**These are two different db's not managed by django.**
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'PARTNER_DB',
'USER': 'root',
'PASSWORD': 'root',
'HOST': '127.0.0.1',
'PORT': '3306',
},
'employeedb': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'EMPLOYEE_DB',
'USER': 'root',
'PASSWORD': 'root',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
**My db models are**
class Partner(models.Model):
client_id = models.CharField(db_column='CLIENT_ID', primary_key=True, max_length=25)
first_name = models.CharField(db_column='FIRST_NAME', max_length=50)
last_name = models.CharField(db_column='LAST_NAME', max_length=50, blank=True, null=True)
mobile = models.CharField(db_column='MOBILE', max_length=10, blank=True, null=True)
active_from = models.DateField(db_column='ACTIVE_FROM')
rm_id = models.CharField(db_column='RM_ID', max_length=10, blank=True, null=True)
preferred_name = models.CharField(db_column='PREFERRED_NAME', max_length=50, blank=True, null=True)
rpm = models.IntegerField(db_column='RPM', blank=True, null=True)
drawdown_protection = models.IntegerField(db_column='DRAWDOWN_PROTECTION', blank=True, null=True)
depository_id = models.CharField(db_column='DEPOSITORY_ID', max_length=45, blank=True, null=True)
dob = models.DateField(db_column='DOB', blank=True, null=True)
account_type = models.CharField(db_column='ACCOUNT_TYPE', max_length=25, blank=True, null=True)
account_status = models.CharField(db_column='ACCOUNT_STATUS', max_length=25, blank=True, null=True)
first_holder_pan_number = models.CharField(db_column='FIRST_HOLDER_PAN_NUMBER', max_length=45, blank=True, null=True)
correspondence_address = models.CharField(db_column='CORRESPONDENCE_ADDRESS', max_length=1000, blank=True, null=True)
permanent_address = models.CharField(db_column='PERMANENT_ADDRESS', max_length=1000, blank=True, null=True)
nominee_name = models.CharField(db_column='NOMINEE_NAME', max_length=100, blank=True, null=True)
second_holder_name = models.CharField(db_column='SECOND_HOLDER_NAME', max_length=100, blank=True, null=True)
second_pan_number = models.CharField(db_column='SECOND_PAN_NUMBER', max_length=45, blank=True, null=True)
mail_id = models.CharField(db_column='MAIL_ID', max_length=200, blank=True, null=True)
bank_name = models.CharField(db_column='BANK_NAME', max_length=1000, blank=True, null=True)
bank_account_number = models.CharField(db_column='BANK_ACCOUNT_NUMBER', max_length=50, blank=True, null=True)
bank_micr_code = models.CharField(db_column='BANK_MICR_CODE', max_length=50, blank=True, null=True)
bank_ifsc_code = models.CharField(db_column='BANK_IFSC_CODE', max_length=50, blank=True, null=True)
class Meta:
managed = False
db_table = 'PARTNER'
class Employee
I want to do a left join with another db, What would be the django equivalent of this query ?
USE PARTNER_DB;
SELECT CLIENT_ID, PARTNER.FIRST_NAME, PARTNER.LAST_NAME,
RPM, DRAWDOWN_PROTECTION, CONCAT(EMPLOYEE_DB.EMPLOYEE.FIRST_NAME, " ", EMPLOYEE_DB.EMPLOYEE.LAST_NAME),
EMPLOYEE_DB.EMPLOYEE.MAIL
FROM PARTNER
LEFT JOIN EMPLOYEE_DB.EMPLOYEE
ON RM_ID = EMPLOYEE_DB.EMPLOYEE.EMP_ID
WHERE CLIENT_ID = 'X1234'
I am using multiple databases in my project and both of these databases are not managed by django.
I tried to dig into django documentation but was unable to find a way to achieve this, instead i bumped into this
[https://docs.djangoproject.com/en/1.11/topics/db/multi-db/#no-cross-database-relations][1].
I am sure that there will be a hack / workaround this. Looking forward to your solutions.
**These are two different db's not managed by django.**
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'PARTNER_DB',
'USER': 'root',
'PASSWORD': 'root',
'HOST': '127.0.0.1',
'PORT': '3306',
},
'employeedb': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'EMPLOYEE_DB',
'USER': 'root',
'PASSWORD': 'root',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
**My db models are**
class Partner(models.Model):
client_id = models.CharField(db_column='CLIENT_ID', primary_key=True, max_length=25)
first_name = models.CharField(db_column='FIRST_NAME', max_length=50)
last_name = models.CharField(db_column='LAST_NAME', max_length=50, blank=True, null=True)
mobile = models.CharField(db_column='MOBILE', max_length=10, blank=True, null=True)
active_from = models.DateField(db_column='ACTIVE_FROM')
rm_id = models.CharField(db_column='RM_ID', max_length=10, blank=True, null=True)
preferred_name = models.CharField(db_column='PREFERRED_NAME', max_length=50, blank=True, null=True)
rpm = models.IntegerField(db_column='RPM', blank=True, null=True)
drawdown_protection = models.IntegerField(db_column='DRAWDOWN_PROTECTION', blank=True, null=True)
depository_id = models.CharField(db_column='DEPOSITORY_ID', max_length=45, blank=True, null=True)
dob = models.DateField(db_column='DOB', blank=True, null=True)
account_type = models.CharField(db_column='ACCOUNT_TYPE', max_length=25, blank=True, null=True)
account_status = models.CharField(db_column='ACCOUNT_STATUS', max_length=25, blank=True, null=True)
first_holder_pan_number = models.CharField(db_column='FIRST_HOLDER_PAN_NUMBER', max_length=45, blank=True, null=True)
correspondence_address = models.CharField(db_column='CORRESPONDENCE_ADDRESS', max_length=1000, blank=True, null=True)
permanent_address = models.CharField(db_column='PERMANENT_ADDRESS', max_length=1000, blank=True, null=True)
nominee_name = models.CharField(db_column='NOMINEE_NAME', max_length=100, blank=True, null=True)
second_holder_name = models.CharField(db_column='SECOND_HOLDER_NAME', max_length=100, blank=True, null=True)
second_pan_number = models.CharField(db_column='SECOND_PAN_NUMBER', max_length=45, blank=True, null=True)
mail_id = models.CharField(db_column='MAIL_ID', max_length=200, blank=True, null=True)
bank_name = models.CharField(db_column='BANK_NAME', max_length=1000, blank=True, null=True)
bank_account_number = models.CharField(db_column='BANK_ACCOUNT_NUMBER', max_length=50, blank=True, null=True)
bank_micr_code = models.CharField(db_column='BANK_MICR_CODE', max_length=50, blank=True, null=True)
bank_ifsc_code = models.CharField(db_column='BANK_IFSC_CODE', max_length=50, blank=True, null=True)
class Meta:
managed = False
db_table = 'PARTNER'
class Employee
(models.Model):
emp_id = models.IntegerField(db_column='EMP_ID', primary_key=True)
first_name = models.CharField(db_column='FIRST_NAME', max_length=100)
last_name = models.CharField(db_column='LAST_NAME', max_length=100)
mail = models.CharField(db_column='MAIL', max_length=100)
class Meta:
managed = False
db_table = 'EMPLOYEE'
[1]: https://docs.djangoproject.com/en/1.11/topics/db/multi-db/#no-cross-database-relations
/r/django
https://redd.it/6r2kwt
emp_id = models.IntegerField(db_column='EMP_ID', primary_key=True)
first_name = models.CharField(db_column='FIRST_NAME', max_length=100)
last_name = models.CharField(db_column='LAST_NAME', max_length=100)
mail = models.CharField(db_column='MAIL', max_length=100)
class Meta:
managed = False
db_table = 'EMPLOYEE'
[1]: https://docs.djangoproject.com/en/1.11/topics/db/multi-db/#no-cross-database-relations
/r/django
https://redd.it/6r2kwt
reddit
[HELP] Left Join between multiple databases • r/django
I want to do a left join with another db, What would be the django equivalent of this query ? USE PARTNER_DB; SELECT CLIENT_ID,...
Just wanna say thanks to flask,sqlalchemy,postgres and redis. I managed to create a server app that handles 7 Million requests per day. (probably more)
Proof:
http://imgur.com/a/n3mfG
I think it's one of my greatest achievement ever since we were only a 2-man team in the server dev.
/r/flask
https://redd.it/6r2gir
Proof:
http://imgur.com/a/n3mfG
I think it's one of my greatest achievement ever since we were only a 2-man team in the server dev.
/r/flask
https://redd.it/6r2gir
Imgur
Imgur: The most awesome images on the Internet
Imgur: The most awesome images on the Internet.
Logging in Python : the definitive guide
https://blog.bordum.dk/logging-tutorial-python.html
/r/Python
https://redd.it/6r5cw6
https://blog.bordum.dk/logging-tutorial-python.html
/r/Python
https://redd.it/6r5cw6
reddit
Logging in Python : the definitive guide • r/Python
15 points and 7 comments so far on reddit
Clustering multiple GPUs from different machines and remotely run Jupyter Notebook
Hello everyone, I am a newcomer here in this community.
I have only 2 GB GPU but my friend has 4GB so I generally train my model on his machine. I normally use Jupyter Notebook and I code in Python. Recently I came to know about "Running a notebook server" and I set up that. Now I can remotely run a jupyter notebook on my machine (client) while the resources are used from my friend's machine (server).
4 GB of GPU is also not sufficient for me. I am curious if I could remotely use GPUs from many of my friends' machine and cluster them and then remotely run the jupyter notebook. Its similar to the server-client model that we previously created but I wish to extend it to multiple "shared-servers" so that I can use all of their GPU's in collaborative and distributive fashion. It is a kind of 'many-to-one' server (many) and client (one) model.
Can anybody help me how can I achieve that in Jupyter Notebook server ?
Or is there any option to remotely use GPU from different machines and run my python code remotely ?
Thanks
LINK - jupyter-notebook.readthedocs.io/en/latest/public_server.html
/r/JupyterNotebooks
https://redd.it/6r76md
Hello everyone, I am a newcomer here in this community.
I have only 2 GB GPU but my friend has 4GB so I generally train my model on his machine. I normally use Jupyter Notebook and I code in Python. Recently I came to know about "Running a notebook server" and I set up that. Now I can remotely run a jupyter notebook on my machine (client) while the resources are used from my friend's machine (server).
4 GB of GPU is also not sufficient for me. I am curious if I could remotely use GPUs from many of my friends' machine and cluster them and then remotely run the jupyter notebook. Its similar to the server-client model that we previously created but I wish to extend it to multiple "shared-servers" so that I can use all of their GPU's in collaborative and distributive fashion. It is a kind of 'many-to-one' server (many) and client (one) model.
Can anybody help me how can I achieve that in Jupyter Notebook server ?
Or is there any option to remotely use GPU from different machines and run my python code remotely ?
Thanks
LINK - jupyter-notebook.readthedocs.io/en/latest/public_server.html
/r/JupyterNotebooks
https://redd.it/6r76md
[P] Introducing Vectorflow: a lightweight neural network library for sparse data (Netflix)
https://medium.com/@NetflixTechBlog/introducing-vectorflow-fe10d7f126b8
/r/MachineLearning
https://redd.it/6r6l0y
https://medium.com/@NetflixTechBlog/introducing-vectorflow-fe10d7f126b8
/r/MachineLearning
https://redd.it/6r6l0y
Medium
Introducing Vectorflow
a lightweight neural network library for sparse data
My first program for today, feeling creative.
>>> true=False
>>> true!=False
False
>>> True!=False
True
/r/Python
https://redd.it/6raocg
>>> true=False
>>> true!=False
False
>>> True!=False
True
/r/Python
https://redd.it/6raocg
reddit
My first program for today, feeling creative. • r/Python
>>> true=False >>> true!=False False >>> True!=False True
I have set up my React frontend. Need a backend to manage user accounts and store data - is Django a good progression?
As mentioned in the title, I have set up the base foundation for my webapp using React/Redux for my front end.
I would like to take it a step further by adding a backend so that users can create accounts, login, and save data.
I have been looking into Firebase as it's recommended but it feels like I won't learn as much about backend / databases since Firebase does a lot of it behinds the scene.
I am considering Django and was wondering if this would be a good progression for me? Where does Django or Firebase fit into the picture?
I have zero experience with anything backend related but want to learn more.
/r/django
https://redd.it/6r9t4a
As mentioned in the title, I have set up the base foundation for my webapp using React/Redux for my front end.
I would like to take it a step further by adding a backend so that users can create accounts, login, and save data.
I have been looking into Firebase as it's recommended but it feels like I won't learn as much about backend / databases since Firebase does a lot of it behinds the scene.
I am considering Django and was wondering if this would be a good progression for me? Where does Django or Firebase fit into the picture?
I have zero experience with anything backend related but want to learn more.
/r/django
https://redd.it/6r9t4a
reddit
I have set up my React frontend. Need a backend to... • r/django
As mentioned in the title, I have set up the base foundation for my webapp using React/Redux for my front end. I would like to take it a step...
Are Django session variables secure?
I am creating an app for use in our organization that will login users based on their Office 365 credentials using OAuth2.0. I am looking at fetching an access token that I will store in a session variable. Right now, though, I am just saving 'oauth_state' into a session variable and setting that variable to 'authorized'. Upon loading of each (non-login view), I am checking whether 'oauth_state' is set to 'authorized'. I'm probably going to change this and store a token the variable and use that to query the MSGraph API for a 200 response upon each page load. Anyways, here is an example of what I am doing:
@never_cache
def authorization(request):
microsoft = OAuth2Session(client_id,scope=scope,redirect_uri=redirect_uri)
token = ""
try:
users = 'https://graph.microsoft.com/v1.0/me' ##msgraph query url-
##This query is purelyjust used to
##authenticate user!
token = microsoft.fetch_token(token_url,client_secret=client_secret,code=request.GET.get('code', '')) ##Code is the authorization code present
##in request URL
header = {'Authorization': 'Bearer ' + token['access_token']}
response = requests.get(url = users, headers = header)
if int(response.status_code) != 200: ##if status code is not 200, then authentication failed. Redirect to login.
print ('Not validated. Return to login.')
request.session.flush()
return redirect('http://localhost:8000/login')
except Exception as e:
print ('User not does not have authentication rights')
request.session.flush()
return redirect('http://localhost:8000/login')
request.session['oauth_state'] = 'authorized'
response = HttpResponseRedirect('http://localhost:8000/search')
return response
I am then using this to check if 'oauth_state' is set to 'authorized'. However, I may change this so that the token is used to query the MS Graph API in each function in order to check if the user has proper permissions or not. Here's an example of what I am doing:
def search(request):
try:
if (str(request.session['oauth_state']) != 'authorized'):
print ('Not authorized')
request.session.flush()
return redirect('http://localhost:8000/login')
except Exception as e:
print ('Not authorized')
request.session.flush()
return redirect('http://localhost:8000/login')
<rest of code>
How insecure is this? Should I possibly be passing in the token to the response header? Or should I get rid of this method, and use django's standard auth and login system? I really appreciated the benefits of OAuth2.0, but if this method compromises our security, I might scrap it.
/r/django
https://redd.it/6r8hg8
I am creating an app for use in our organization that will login users based on their Office 365 credentials using OAuth2.0. I am looking at fetching an access token that I will store in a session variable. Right now, though, I am just saving 'oauth_state' into a session variable and setting that variable to 'authorized'. Upon loading of each (non-login view), I am checking whether 'oauth_state' is set to 'authorized'. I'm probably going to change this and store a token the variable and use that to query the MSGraph API for a 200 response upon each page load. Anyways, here is an example of what I am doing:
@never_cache
def authorization(request):
microsoft = OAuth2Session(client_id,scope=scope,redirect_uri=redirect_uri)
token = ""
try:
users = 'https://graph.microsoft.com/v1.0/me' ##msgraph query url-
##This query is purelyjust used to
##authenticate user!
token = microsoft.fetch_token(token_url,client_secret=client_secret,code=request.GET.get('code', '')) ##Code is the authorization code present
##in request URL
header = {'Authorization': 'Bearer ' + token['access_token']}
response = requests.get(url = users, headers = header)
if int(response.status_code) != 200: ##if status code is not 200, then authentication failed. Redirect to login.
print ('Not validated. Return to login.')
request.session.flush()
return redirect('http://localhost:8000/login')
except Exception as e:
print ('User not does not have authentication rights')
request.session.flush()
return redirect('http://localhost:8000/login')
request.session['oauth_state'] = 'authorized'
response = HttpResponseRedirect('http://localhost:8000/search')
return response
I am then using this to check if 'oauth_state' is set to 'authorized'. However, I may change this so that the token is used to query the MS Graph API in each function in order to check if the user has proper permissions or not. Here's an example of what I am doing:
def search(request):
try:
if (str(request.session['oauth_state']) != 'authorized'):
print ('Not authorized')
request.session.flush()
return redirect('http://localhost:8000/login')
except Exception as e:
print ('Not authorized')
request.session.flush()
return redirect('http://localhost:8000/login')
<rest of code>
How insecure is this? Should I possibly be passing in the token to the response header? Or should I get rid of this method, and use django's standard auth and login system? I really appreciated the benefits of OAuth2.0, but if this method compromises our security, I might scrap it.
/r/django
https://redd.it/6r8hg8
reddit
Are Django session variables secure? • r/django
I am creating an app for use in our organization that will login users based on their Office 365 credentials using OAuth2.0. I am looking at...