CODE SNIPPETS

CODESNIPPETS FOR .NET, SQL, JAVASCRIPT, JQUERY and more

  1. Python

Python

How to download a file using Python

 Administrator
 April 21, 2015
0 Comments

To download a file using Python you can use the snippet below.

Sample Python

import urllib.request
import shutil

# file_name = target file name
with urllib.request.urlopen(url) as response, open(file_name, 'wb') as out_file:
    shutil.copyfileobj(response, out_file)

  Posted in Python
  Tagged dl, download, file, files, from, get, http, internet, load, py, Python, retrieve, save, URL, urllib, web
  Permalink

How to check if a path is a Directory in Python

 Administrator
 February 21, 2015
3 Comments

To check if a path is a Directory in Python you can use the snippet below.

Sample Python

import os

print(os.path.isdir("/myfolder/folder1"))

  Posted in Python
  Tagged check, dir, directories, Directory, file, folder, folders, if, import, is, or, OS, Path, py, Python
  Permalink

How to check if Folder exists in Python

 Administrator
 February 21, 2015
4 Comments

To check if Folder exists in Python you can use the snippet below.

import os
print(os.path.exists("/myfolder/folder1"))

  Posted in Python
  Tagged check, dir, directories, Directory, exist, existance, exists, folder, if, import, OS, Path, paths, py, Python
  Permalink

How to check if a Object has an Attribute in Python

 Administrator
 February 21, 2015
6 Comments

To check if a Object has an Attribute in Python you can use the snippet below.

Sample Python

if hasattr(myObject, 'myAttributeName'): # myObject.myAttributeName exists.

  Posted in Python
  Tagged att, attr, Attribute, attributes, check, contains, exist, exists, has, have, object, properties, property, py, Python
  Permalink

How to check if a variable exists in Python

 Administrator
 February 21, 2015
4 Comments

To check if a variable exists in Python, you can use the snippet below.

Sample Python

if 'myVariable' in locals(): # myVariable exists locally.
if 'myVariable' in globals(): # myVariable exists globally.

  Posted in Python
  Tagged check, determine, evaluate, exist, exists, global, globally, globals, if, local, locally, locals, py, Python, var, variable, variables, vars
  Permalink

how to combine two lists using Python

 Administrator
 February 21, 2015
6 Comments

To combine two lists using Python you can use the following snippet.

Sample Python

create a new list

list = list_1 + list_2 #creates a new list

extend a list

list_1.extend(list_2) #extends list 1

  Posted in Python
  Tagged array, arrays, collections, combine, concat, list, lists, merge, py, Python
  Permalink

How to split a string to list in Python

 Administrator
 February 21, 2015
3 Comments

To split a String to List in Python, simply use the split() function.

Sample Python

splittedWords = text.split()

  Posted in Python
  Tagged char, character, characters, chars, collection, list, py, Python, split, splitted, String, Strings, word, words
  Permalink

How to do a string contains in Python

 Administrator
 February 16, 2015
2 Comments

To use String.Contains in Python you can use the IN operator.

testString = "Hello World 2015"
if "World" not in testString:
print("World is not in String")
else:
print("World is in String")

  Posted in Python
  Tagged char, characters, chars, contain, contains, find, in, is, Python, String, substring
  Permalink

How to convert string to Int or Float in Python

 Administrator
 February 16, 2015
3 Comments

To convert string to Int or Float in Python you can use the following snippet.

Sample Python

NumbertoConvert = "321.1234"
print(float(NumbertoConvert)) # prints out 321.1234
print(int(float(NumbertoConvert))) # prints out 321

  Posted in Python
  Tagged conversion, convert, Converter, Float, floats, int, Integer, py, Python, String, Strings
  Permalink

How to add a new Value to a Dictionary in Python

 Administrator
 February 16, 2015
4 Comments

To add a new Value to a Dictionary in Python you can use one of the following ways.

Sample Python

myDict['key'] = 'value'

or

Sample Python

myDict = {'key':'value'}

  Posted in Python
  Tagged add, dict, dictionaries, key, keys, keyvaluepair, new, pair, py, Python, value, values
  Permalink

Posts navigation

Older posts

Search


Search for:

Navigation


  • Menu
    • DISCLAIMER / HAFTUNGSAUSSCHLUSS
    • IMPRINT / IMPRESSUM
    • PRIVACY POLICY / DATENSCHUTZ
    • Submit a Snippet
  • Projects
    • Fesslersoft.Extensions
    • Tornadocapture
  • Tools
    • Base64 Encoder/Decoder
    • Colorpicker
    • MD5 Hash Creator
    • UUID/GUID Generator
    • XML Formatter
Subscribe via RSS

Meta


  • Register
  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Categories


  • .NET
  • Android
  • AngularJs
  • Announcements
  • Batch
  • C
  • C#
  • C-PlusPlus
  • CSS
  • Devexpress
  • HTML / HTTP / WEB
  • ios
  • Java
  • Javascript
  • jQuery
  • Microsoft SQL Server
  • Mobile
  • Most Read Articles
  • MySql
  • NuGet
  • Objective-C
  • Oracle
  • PHP
  • Powershell
  • Python
  • Regex
  • Ruby
  • SQLite
  • VB.Net
  • VB6
  • VBA
  • VBScript
  • Wordpress
  • XML
  • XSD
  • XSL

Popular Posts


The 10 most visited posts in last 30 days:
  • How to remove unicode characters from a string in C# and VB.NET
  • How to refresh the current Android Fragment
  • How to convert Stream to ByteArray in C# and VB.NET
  • How to make a multicolumn listbox in C# and VB.NET
  • How to get the current path using VBScript
  • How to extract a password protected zip file using DotNetZip in C# and VB.NET
  • How to join two lists in C# and VB.NET
  • How to remove class after delay in jQuery
  • How to cast a Integer or String to Enum in C# and VB.NET
  • How to Split a String at newline in C# and VB.NET

Recent Posts


  • How to get the current path using VBScript
  • How to disable all links using jQuery
  • How to remove class after delay in jQuery
  • How to check if a value is a double value in Android (Java)
  • How to refresh the current Android Fragment

Recent Comments


  • CodeSnippetBlog on How to get the current path using VBScript
  • AllCodeSnippets on How to get the current path using VBScript
  • Realliferulor on How to get the current path using VBScript
  • Manav6677 on How to disable all links using jQuery
  • javascriptd on How to disable all links using jQuery

Archives


  • August 2016
  • June 2016
  • December 2015
  • November 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • April 2015
  • March 2015
  • February 2015
  • January 2015
  • November 2014
  • August 2014
  • July 2014
  • June 2014
  • May 2014
Back to top

Most used Tags


.net all array C# char character characters chars check convert csharp css Directory Extension file files folder get html IO is Java javascript jQuery js list net php Python query remove retrieve select SQL String Strings System to vb.net Visual Studio 2005 Visual Studio 2008 Visual Studio 2010 Visual Studio 2012 Visual Studio 2013 XML

Copyright © 2019 CODE SNIPPETS. Powered by WordPress and Alétheia.