Change language

Python script to open google map location on clipboard

| |

Here’s a step-by-step process:

  1. Create Address_string from the command line: command line arguments can be read through the sys module. The sys.argv array has the first element as the filename and the remaining elements as command line arguments, which are separated into different elements by spaces, like raw_input (). Split (). Therefore, if the length of sys.argv is greater than 1, we can be sure that the command line arguments are passed. 
    Since sys.argv is a list of strings, it can be passed to the join () method, which returns a single string value. Since the first element — this is the filename, which is not needed, we can slice the list and join from the second element onwards.

    # File name -

    import sys

    print ’’ . join (sys.argv [ 1 :])

     If we run""" python New Delhi The output of the program would be New Delhi. 
  2. Open your web browser: we will use the web browser module to open the browser. The web browser plug-in has a open () method that can launch a web browser at the specified URL. For example, the script below will open a web browser to the Python.Engineering home page.

    import webbrowser

    webbrowser. open ( )

  3. Search URL. Now when we go to Google Maps and search for Google maps, the URL turns out to be unreasonable and lacks a clear pattern as shown below.,77.4077907,17z/data=!3m1!4b1!4m5! 3m4! 1s0x390ce626851f7009: 0x621185133cfd1ad1! 8m2! 3d28.5011226! 4d77.4099794? gl = en

    Websites often add extra text to the URL for additional tasks such as customization and tracking. However, you may notice that the initial portion of the URL — this is, where Python.Engineering is our search keyword. 
    Also, for example, say, when looking for New Delhi instead of New Delhi, if we write only New Delhi, the + sign is inserted in the right places on its own, which makes our task even easier. 
    Therefore, the final URL can be taken as Address_String / .

  4. Combining the two and ending the script: A python script to open the given command line address is given below. There will be two imported modules, a web browser to open the browser at the specified URL and sys to work with command line arguments.
    • Step One & # 8212 ; check if any command line is set or not, which is done with len (sys.argv).
    • We then use the join method to form the address bar of the place to look for in Google Maps.
    • Finally, when we get the address, we open the browser to the URL using the open () method of the webbrowser module.

    The program is launched via CMD (windows) or terminal ( Linux) in the following format:

    """ python [File Name] [Address to be searched] For eg. & gt;"" python Python.Engineering 

    # File name -

    import sys, webbrowser

    if len (sys.argv)"  1 # Argument passed

    map_string = ’ ’ . join (sys.argv [ 1 :])

    webbrowser. open ( + map_string)


    else :

    print "Pass the string as command line argument, Try Aga in "


    """ python SeeksforGeeks The above command will open map of  Python.Engineering  in the web browser. 

This article courtesy of Harshit Agrawal . If you are as Python.Engineering and would like to contribute, you can also write an article using or by posting an article contribute @ See my article appearing on the Python.Engineering homepage and help other geeks.

Please post comments if you find anything wrong or if you’d like to share more information on the topic discussed above.


Learn programming in R: courses


Best Python online courses for 2022


Best laptop for Fortnite


Best laptop for Excel


Best laptop for Solidworks


Best laptop for Roblox


Best computer for crypto mining


Best laptop for Sims 4


Latest questions


psycopg2: insert multiple rows with one query

12 answers


How to convert Nonetype to int or string?

12 answers


How to specify multiple return types using type-hints

12 answers


Javascript Error: IPython is not defined in JupyterLab

12 answers



Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method