پایتون؛ دانش متفرقه

#short keys

ctrl + /        comment or uncomment block of code

alt + (select lines)  arrow keys       move up and down selected lines

alt + shift + (select lines)  arrow keys         duplicate selected lines

################################

#notes

range type compare with list, use  little memory

###

pass ==> use instead of  null block

###

install pandas from Jupyter command line

!pip install -U pandas


############ define an array and append items to it

import numpy

x = range(0, 100)

z = []

for i in range(0, 100):

z.append( x[i] )

print (len(z))


######## library version

import pandas 

pandas.__version__


import numpy

numpy.__version__

#####################

some useful extensions

pylint  

Linting highlights semantic and stylistic problems in your Python source code

==> Shift + Ctrl + M to watch problem console enhanced with pylint

autopep4

==> Formatter extension for Visual Studio Code using autopep8, Shift+Alt+F

==> File>Preferences>Setting>Editor: FormatOnSave (select it)

Code Runner

==> use ctrl+alt+n to execute code 

##############

PEP 8 – Style Guide for Python Code

https://peps.python.org/pep-0008/

###############

Python implementations:

CPython ==> C

Jython==> Java        so, some java codes could run in this implementation

IronPython ==> C#    so, some c# codes could run in this implementation

PyPy ==> subset of Python

##################

Connect to SAP:

reference: https://community.sap.com/t5/technology-blogs-by-members/connecting-python-with-sap-step-by-step-guide/ba-p/13452893

*download nwrfc750P_12-7000275 from SAP site and install 

*Create a folder ‘nwrfcsdk’ in C:\

*Extract the contents of zip file (nwrfc750P_6-70002755.zip) in the path C:\nwrfcsdk

*You'll see another nwrfcsdk folder inside C:\nwrfcsdk

*Cut and paste the contents from C:\nwrfcsdk\nwrfcsdk and move it to C:\nwrfcsdk folder

*Add C:\nwrfcsdk\bin, C:\nwrfcsdk\lib into windows envirenment path


2-install cython with "pip install cython"

3-install pyrfc with "pip install --no-binary pyrfc pyrfc"


"""Here is sample code connect to SAP"""


from pyrfc import Connection


# Establish connection to SAP system

conn = Connection(ashost='192.168.????', sysnr='00',

                  client='450', user='?????', passwd='?????')


# Define RFC function module to call

rfc_name = 'RFC_READ_TABLE'


# Parameters for RFC function module

table_name = 'USR02'

query_table = {

    'QUERY_TABLE': table_name,

    'DELIMITER': '|',  # Delimiter for result

    # SQL WHERE clause

    'OPTIONS': [{'TEXT': "BNAME LIKE 'A.%' and ERDAT > '20230803'"}],

    # Fields to retrieve

    'FIELDS': [{'FIELDNAME': 'BNAME'}, {'FIELDNAME': 'USTYP'}]

}


# Call RFC function module

result = conn.call(rfc_name, **query_table)


# Process result

if result['DATA']:

    for row in result['DATA']:

        fields = row['WA'].split('|')  # Split row by delimiter

        print(fields)

else:

    print("No data returned.")

# Close connection

conn.close()

############################################################################################
نظرات 0 + ارسال نظر
امکان ثبت نظر جدید برای این مطلب وجود ندارد.