Posts

Get started with Python on Mac

These are the steps Installing Python If you want to run an existing project or package from another source (not your own code) Installing packages from Github If you want to get coding: Fire up IDLE and use that as your coding tools Other more advanced tools do also exist

Installing packages from GitHub

Make sure that you have Pyhon3 and PIP/PIP3 In Terminal run this line: pip3 install git + https :// github . com / jkbr / httpie . git The above is an example of httpie package. Replace the URL with the relevante package OR... You can also install Python packages from Github by cloning the repository. First run this via Terminal in the desired folder to download: git clone https :// github . com / jkbr / httpie . git Then start the installation by running whatever setup or install file is associated: sudo python setup . py install Tip: When your in Terminal, use the "LS" command to show whats in the directory. 

How to read from a table in MSSQL with Python

I use this code import pyodbc conn = pyodbc.connect( 'driver={ODBC Driver 17 for SQL Server};' 'server=XXXXXXXXXXXX;' 'database=YYYYYYYYYYY;' 'uid=ZZZZZZZZZZZ;' 'pwd=QQQQQQQQQQ;' ) rs = conn.cursor() rs.execute( 'SELECT top 10 * FROM quant_test with (NOLOCK)' ) for row in rs: print (row)

How to insert in MSSQL with Python

I used this code that seems to do the trick: import pyodbc conn = pyodbc.connect( 'driver={ODBC Driver 17 for SQL Server};' 'server=XXXXXXXXXX;' 'database=YYYYYY;' 'uid=ZZZZZZ;' 'pwd=QQQQQQQQ;' ) rs = conn.cursor() rs.execute( ''' INSERT INTO quant_test (symbol,stockprice) VALUES ('AAPL',180) ''' ) conn.commit() rs.execute(''' INSERT INTO quant_test (symbol,stockprice) VALUES ('AAPL',180) ''') conn.commit()

How to make a script that refreshes / loades every n-second in Python

I used this simple code: import time import datetime intervalInSeconds = 1.0 starttime=time.time() while True : currentTime = datetime.datetime.now() print (currentTime) time.sleep(intervalInSeconds - ((time.time() - starttime) % intervalInSeconds))

Installing Microsoft ODBC Driver to connect to SQL from Python on Mac OS X

What a nightmare it's been for me to figure this out. Remember to have homebrew installed in advance. Then run this in terminal: brew install msodbcsql At first, it didn't work for me, saying something about taps was empty and no available formulas. Then I found out I needed to run this command in Terminal rm -rf /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core; brew update Then I could run brew install msodbcsql ... but not successfully. OK, so I tried another approach /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"  brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release brew update  brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release followed by...   brew install msodbcsql17 mssql-tools This seems to have worked! My driver is now  ODBC Driver 17 for SQL Server Ressources: https://do...