[HOWTO] Program using Python


Recommended Posts

Lesson #1

Part 1: Say Hello!

Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python's elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms.

This first tutorial is meant to be an informal introduction to programming with python. It will describe how to make a basic routine from the category of the "Hello World!" program. It is very advisable to first read the python documentation that comes with your python distribution. What will be covered here is nothing but the basics, in an informal way. Other more advanced lessons will be posted afterwards. This tutorial is made using a Linux system, some of the bellow may not apply if you are using Windows, especially the header section. Read your python manual about this part.

OK, let's start. There are two ways of running simple python code like the one that is going to be shown in this tutorial:

- Interactively by opening a console and typing "python" (this will start the python interpreter interactively and "run as you type");

- Creating a python file and running it.

Here we will cover the method of creating a python file, as it is more easy to keep track of the code this way, but please feel free to use any method you wish.

Creating the python file:

  • Create a new empty text file named "hello.py";
  • Open it with an editor of your choice. An editor that supports python syntax highlighting and indentation will be preferred. To program in python my favorite editor is kate, feel free to use your editor of choice;
  • Change the file header to reflect that this is a python program and declare what encoding it will use. Will not go into details explaining this section, the header will be different if for instance you are using Windows to program. Please consult your python manual to find out more about this section.
    Add the following lines to the beginning of your file:
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-


  • The instruction that prints the actual hello to the world. Add the following line to your file:
    print "Hello neowin.net!"


  • That's it! There is not further step, the "Hello World!" program is now complete. Just save the file, open a terminal on the directory where you have your python file and run it by typing on the terminal:
    python hello.py

The entire "Hello World!" program will look something like this (newlines added to make the code more readable):

#!/usr/bin/env python
# -*- coding: utf-8 -*-


print "Hello neowin.net!"

The output of our little program will, of course, be:

Hello neowin.net!

Understanding the code:

In our code we only have one line of instruction. This line does what it says, prints the "Hello neowin.net!" sentence on screen. If you understand C programming, this will be the equivalent of the printf or puts instruction.

print "Hello neowin.net!"

Learning tips:

Don't just copy>paste the code, take time to understand what the code does.

______________________________________________________________________

Part 2: Calculate this.

In this part we will be doing a calculator that given two members and an operation will say the result between those two same members to the user! This is the same as saying we will be doing a program similar to the previous "Hello World!" program, but that instead of just printing some sentence it will be printing the result of a simple arithmetic operation between two integer numbers, in the most lame way possible.

  • Create a new empty text file named "talking_calculator.py";
  • Copy>paste the code bellow.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

#	Talking calculator by Lechio
#	This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
#	the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
#	Copyright (C) 2008   Lechio (TM)




#The import statement.
import sys





#Analyze the arguments provided.
try:
	#First argument provided. At the same time we check if this is argument is of int type.
	member1 = int( sys.argv[1] )

	#Second argument provided, the operation type.
	operation = str( sys.argv[2] )

	#Third argument provided. At the same time we check if this is argument is of int type.
	member2 = int	( sys.argv[3] )


except:
	#Print an error if the arguments are invalid.
	print "Invalid data provided.","Correct usage:"
	print "member1 operation member2"

	sys.exit(1)




#Our operation types:

if sys.argv[2]=="+" or sys.argv[2]=="plus" or sys.argv[2]=="sum":#Sum
	result = member1 + member2#calculate
	pretty_operation_name = "sum"

elif sys.argv[2]=="-" or sys.argv[2]=="minus" or sys.argv[2]=="subtract":#Subtraction
	result = member1 - member2#calculate
	pretty_operation_name = "subtraction"

elif sys.argv[2]=="*" or sys.argv[2]=="X" or sys.argv[2]=="x" or sys.argv[2]=="times" or sys.argv[2]=="multiply":#Multiplication
	result = member1 * member2#calculate
	pretty_operation_name = "multiplication"

elif sys.argv[2]=="/" or sys.argv[2]=="by" or sys.argv[2]=="divide":#Division
	result = member1 / member2#calculate
	pretty_operation_name = "division"

else:#Invalid operation type.
	print "Operation failed! Invalid operation type."
	sys.exit(1)






#Printing the result:
try:
	#Check if the result obtained is of type int.
	result = int(result)



	#Print the result in a pretty form.
	print "\n\n\n"#print a few empty lines.
	print "\t\t\tThe" , pretty_operation_name , 'of' , member1 , "and", sys.argv[3] , "is:", result
	print "\n\n\n"#print a few empty lines.


except:
	#Print an error if the result isn't of type int.
	print "Operation failed! Invalid data obtained, the result is not of type int."



#Talking calculator ends here

Do not be overwhelmed by all of these new things in the code, these will now be explained step by step.

The header.

We've already covered this part in our previous "Hello World!" program. Only a new thing was added, the comments. One line comments in python can be done by putting a '#' in the part of the code where we want to make the comment, all that is to the right of the '#' char will be ignored by the python interpreter and seen as comment. Comments are important if you want to keep your code readable to others (and even to you). A good practice is to always make a comment on an important part of the code, explaining what it does for instance.

Here we've just included simple comments that contain the name of the program, author, license type and copyright notice.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

#	Talking calculator by Lechio
#	This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
#	the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
#	Copyright (C) 2008   Lechio (TM)

The import statment.

Python is a modular language. This means we can import anything we want from the modules that come with a python distribution or import our own modules (we will get to that later), and use those to extend the capabilities of our program.

In this example we've imported the "sys" module. This is one of the most important modules (if we can attribute that role to any) from python:

"This module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. It is always available".

#The import statment.
import sys

Analyze the arguments provided.

This part of the code analyses the arguments provided by the user and checks if those are valid.

The "try - except" is used here to validate the arguments. This statement analyses the conditions right after the "try:" part, if these conditions aren't valid for some reason, the code after the "except:" part will be executed.

In this example we check if the first and third argument ( sys.argv[1] and sys.argv[3] ) provided by the user are (or can be converted to) "int" type. If that is possible we attribute those values to two variables (member1 and member2) for later use and attribute the second argument provided by the user to another variable (operation). If that is not possible then the part after the "except:" will be executed to print an error message and to terminate the program here ("sys.exit(1)").

#Analyze the arguments provided.
try:
	#First argument provided. At the same time we check if this is argument is of int type.
	member1 = int( sys.argv[1] )

	#Second argument provided, the operation type.
	operation = str( sys.argv[2] )

	#Third argument provided. At the same time we check if this is argument is of int type.
	member2 = int	( sys.argv[3] )


except:
	#Print an error if the arguments are invalid.
	print "Invalid data provided.","Correct usage:"
	print "member1 operation member2"

	sys.exit(1)

Operation type and calculations.

This part of the code will make the calculations. The "if (...) elif (...) else" condition is used to check what type of operation should be performed. The second argument provided by the user ( sys.argv[2] ) is analyzed, the correspondent operation will be made and the resulting value of that operation will attributed to a variable (result). At the same time we attribute a value to another variable for later printing (pretty_operation_name). If the operation type is not of a valid type (valid for us) the else part will be used to print an error message and terminate the program.

#Our operation types:

if sys.argv[2]=="+" or sys.argv[2]=="plus" or sys.argv[2]=="sum":#Sum
	result = member1 + member2#calculate
	pretty_operation_name = "sum"

elif sys.argv[2]=="-" or sys.argv[2]=="minus" or sys.argv[2]=="subtract":#Subtraction
	result = member1 - member2#calculate
	pretty_operation_name = "subtraction"

elif sys.argv[2]=="*" or sys.argv[2]=="X" or sys.argv[2]=="x" or sys.argv[2]=="times" or sys.argv[2]=="multiply":#Multiplication
	result = member1 * member2#calculate
	pretty_operation_name = "multiplication"

elif sys.argv[2]=="/" or sys.argv[2]=="by" or sys.argv[2]=="divide":#Division
	result = member1 / member2#calculate
	pretty_operation_name = "division"

else:#Invalid operation type.
	print "Operation failed! Invalid operation type."
	sys.exit(1)

Printing the result.

This final part of the code will print the result.

It checks if the result is of type "int" and prints it on screen in form of a sentence.

#Printing the result:
try:
	#Check if the result obtained is of type int.
	result = int(result)



	#Print the result in a pretty form.
	print "\n\n\n"#print a few empty lines.
	print "\t\t\tThe" , pretty_operation_name , 'of' , member1 , "and", sys.argv[3] , "is:", result
	print "\n\n\n"#print a few empty lines.


except:
	#Print an error if the result isn't of type int.
	print "Operation failed! Invalid data obtained, the result is not of type int."

To run this program just save the file, open a terminal on the directory where you have your python file and run it by typing on the terminal:

python talking_calculator.py 1337 plus 1337

Change the numbers and the operation type.

Learning tips:

Try to find a way to do a more advanced calculator, by making it able to perform more complex calculations.

This completes this part of lesson #1.

______________________________________________________________________

Part 3: Get in func.

What we've manged to achieve so far is nothing but a big pile of instructions that get executed one after the other. What if we could organize this a bit more? And at the same time optimize our code for execution?

In comes the functions.

Again, this is yeat another "Hello World!" type program. Nothing too advanced will be done here.

  • Create a new empty text file named "get_in_func.py";
  • Copy>paste the code bellow.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

#	Get in func by Lechio
#	This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
#	the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
#	Copyright (C) 2008   Lechio (TM)



#The import statement.
import sys



#Who to salute.
try:who=sys.argv[1]
except:who="Mr. Bill"

#Way to salute.
try:way=sys.argv[2]
except:way="shacking hands with you"

#How to salute.
try:how=sys.argv[3]
except:how="cordial"




def salute( who_to_salute , way_to_salute , how_to_salute ):
	"""Salute the individual"""

	print "\n\n\n"#print a few empty lines.
	print "I slatute you" , who_to_salute , "by" , way_to_salute , "in the most" , how_to_salute , "way."
	print "\n\n\n"#print a few empty lines.



#Run the salutation function
salute( who , way , how )



#Get in func ends here.

Getting the arguments.

Get the arguments provided by the user and store them in a variable. Default those when not found.

#Who to salute.
try:who=sys.argv[1]
except:who="Mr. Bill"

#Way to salute.
try:way=sys.argv[2]
except:way="shacking hands with you"

#How to salute.
try:how=sys.argv[3]
except:how="cordial"

The function.

In this part of the code we declare and write our function. This function takes 3 parameters: "who_to_salute" , "way_to_salute" , "how_to_salute". We will need to provide those arguments when calling it later.

def salute( who_to_salute , way_to_salute , how_to_salute ):
	"""Salute the individual"""

	print "\n\n\n"#print a few empty lines.
	print "I slatute you" , who_to_salute , "by" , way_to_salute , "in the most" , how_to_salute , "way."
	print "\n\n\n"#print a few empty lines.

Call the function.

Here we call the function with our 3 arguments.

#Run the salutation function
salute( who , way , how )

To run this program just save the file, open a terminal on the directory where you have your python file and run it by typing on the terminal:

python get_in_func.py "Mr.John" "shacking hands with you" "cordial"

Change the arguments.

Learning tips:

Make another more complex function, with a few more arguments.

This completes this part of lesson #1.

______________________________________________________________________

Part 4: Classified.

We've already seen how useful functions can be to help keep our code optimized and organized too. But what if we could go one step further and get our code even more optimized and organized, Classifying it into sections where we could write our code inside functions and keep it really organized?

In comes the Classes.

If you program in C++ you will recognize these. For this example (for a change) we are going to make something really "useful", a program that checks a Gmail inbox and tells the mail count! Pretty lame thing to be doing, with so many mail applications that can do this task, oh well... A Gmail checker in under 50 lines of code:

  • Create a new empty text file named "get_my_gmail.py";
  • Copy>paste the code bellow.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

#	Script from Adrien Vermeulen made for Aero-AIO superkaramba theme
#	Small modifications by Lechio
#	This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
#	the Free Software Foundation; either version 3 of the License, or (at your option) any later version.


import os,re,sys



#This outputs the number of messages of mailbox. Usage: get_my_gmail.py [LOGIN] [PASSWORD]
class GetGmail:
	def __init__ (self, login, password ):
		self.getGMailNum(login, password)


	def getGMailNum(self, login, password):
		password = password.replace("@","%40")

		#Get mail count (requires wget)
		f=os.popen("wget  -qO - --timeout=10 --no-check-certificate https://" + str(login) + ":" + str(password) + "@mail.google.com/mail/feed/atom")
		a=f.read()
		f.close()

		match=re.search("<fullcount>([0-9]+)</fullcount>",a)

		print "\n\n\n"#print a few empty lines.
		if (match != None):#Print the mail count
			print "\t\t\tYou have ", str(match.group(1)), " message(s)."
		else:
			print "\t\t\tCould not check Gmail"

		print "\n\n\n"#print a few empty lines.


#Call the GetGmail class with the arguments provided by the user, print an error if it fails.
try:
	login=str(sys.argv[1])
	passwd=str(sys.argv[2])
except:
	print "\t\t\tCould not check Gmail. Usage"
	print "\t\t\tpython get_my_gmail.py LOGIN PASSWORD"
else:
	GetGmail(login,passwd)

The Class.

Notice how we declare our class with no arguments. Arguments are then provided to the "__init__" function. This function is always present in a class and runs (initializes) with the arguments provided to call this class. After the "__init__" function we then can declare other functions, these functions can use global variables or private variables that belong only to this class. Prefixing the term "self" will indicate that a member belongs to this class, may it be a variable or a function.

In our code we have the "__init__" function initializing with two arguments (login and password), it then calls the "getGMailNum" function with these two same arguments. We can initialize our class with any function or code we want. We can also call/use a member from this class from outside the class, by prefixing the name of this class to the member we will be using. Code gets contained.

#This outputs the number of messages of mailbox. Usage: get_my_gmail.py [LOGIN] [PASSWORD]
class GetGmail:
	def __init__ (self, login, password ):
		self.getGMailNum(login, password)


	def getGMailNum(self, login, password):
		password = password.replace("@","%40")

		#Get mail count (requires wget)
		f=os.popen("wget  -qO - --timeout=10 --no-check-certificate https://" + str(login) + ":" + str(password) + "@mail.google.com/mail/feed/atom")
		a=f.read()
		f.close()

		match=re.search("<fullcount>([0-9]+)</fullcount>",a)

		print "\n\n\n"#print a few empty lines.
		if (match != None):#Print the mail count
			print "\t\t\tYou have ", str(match.group(1)), " message(s)."
		else:
			print "\t\t\tCould not check Gmail"

		print "\n\n\n"#print a few empty lines.

To run this program just save the file, open a terminal on the directory where you have your python file and run it by typing on the terminal:

python get_my_gmail.py GMAIL_LOGIN GMAIL_PASSWORD

Change the arguments.

Learning tips:

Make other classes and try to use members from outside those classes.

This completes this part of lesson #1.

______________________________________________________________________

Part 5: Hello tool.

Till now we've only made CLI type of programs. Those would print some useless text in our console and quit. What if we could do those in a graphical way and have that same useless text printed using a nice graphical window?

In comes the graphical toolkits.

Python with his modular feature has the possibility of using a lot of graphical interfaces. GTK, QT, Tcl/Tk are some of the most commonly used but there are many, many more. It's a matter of choice.

In this example we will be using Tcl/Tk. This toolkit is one of the more easy and basic ones, a good way to start making graphical interfaces. To use this toolkit, it must (of course) be installed in the system, install the "python-tk" package first if it isn't yet installed.

A graphical "Hello World!" type program in 35 lines of code:

  • Create a new empty text file named "hello_tool.py";
  • Copy>paste the code bellow.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

#	This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
#	the Free Software Foundation; either version 3 of the License, or (at your option) any later version.


import sys

#Import all the components from the Tkinter module. Close everything if the module is not available.
try:from Tkinter import *
except:sys.exit(1)


class Window(Frame):
	def __init__(self, parent=None):
		Frame.__init__(self, parent)
		self.pack()
		self.helloNeowin()


	def helloNeowin(self):
		self.helloButt = Button(self)
		self.helloButt["fg"] = "blue"
		self.helloButt["text"] = "Hello neowin.net!"
		self.helloButt["command"] = self.quit
		self.helloButt.pack()
		self.lift()



if __name__ == "__main__":
	mainWin = Tk()
	app = Window(parent=mainWin)
	app.mainloop()

The imports.

To use the Tk libs we will, of course, need to import them. Here we are using "from Tkinter import *" as it is a more convenient way for us to import all the Tkinter components. We could instead use "import Tkinter", but that would require us to append the name "Tkinter" to every Tkinter component used implying more typing for us, we don't need that...

import sys

#Import all the components from the Tkinter module. Close everything if the module is not available.
try:from Tkinter import *
except:sys.exit(1)

Building the widgets.

We've already seen how classes work. This is the class where we build our widgets. The main window is a simple frame available from our Tkinter module. To find out more about this module it would be a good idea to do a reading on the modules documentation. Using the command "pydoc -w Tkinter" will generate the documentation for this module in form of an HTML file.

class Window(Frame):
	def __init__(self, parent=None):
		Frame.__init__(self, parent)
		self.pack()
		self.helloNeowin()


	def helloNeowin(self):
		self.helloButt = Button(self)
		self.helloButt["fg"] = "blue"
		self.helloButt["text"] = "Hello neowin.net!"
		self.helloButt["command"] = self.quit
		self.helloButt.pack()
		self.lift()

Calling the widget builder and looping the window.

This get2 executed when the application is invoked. It's used to call our class above so the widget can be created. It also creates a loop so the window executes until it quits.

if __name__ == "__main__":
	mainWin = Tk()
	app = Window(parent=mainWin)
	app.mainloop()

To run this program just save the file, open a terminal on the directory where you have your python file and run it by typing on the terminal:

python hello_tool.py

post-52106-1228751780.jpg

Learning tips:

Make it use other widgets from the Tkinter module.

This completes this part of lesson #1.

This concludes lesson #1.

Proceed to Lesson #2

Edited by Lechio
Link to comment
https://www.neowin.net/forum/topic/706942-howto-program-using-python/
Share on other sites

Thank you. :)

This one is more of an introduction than anything else. Hope to be able to provide some more lessons. With the help and input of everyone who wants to help out in making this a complete, yet readable tutorial on how to make simple scripts and even more advanced programs using the python language.

  • 3 weeks later...
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Windows 11 version 26H2 is now available for testing in the latest preview build by Taras Buria Friday Windows 11 preview builds are here. Insiders in the Experimental (formerly Dev) and Beta Channel can download builds 26300.8697 and 26220.8690. There are no new features, but Microsoft is officially moving the Experimental Channel to version 26H2. In addition, Microsoft is improving the copy dialog in File Explorer, the Start menu reliability, and fixing virtualization issues. Here is the changelog: [General] With today’s build, Windows Insiders in the Experimental channel will see the versioning updated under Settings > System > About (and winver) to version 26H2. For more information, see the Windows Insiders blog. [File Explorer] We’ve improved the visual consistency and reliability of the Copy dialog in Dark mode, including its launch experience and the expanded progress view. [Start menu] - Also available in Beta Improved reliability of Start menu reflecting newly installed or removed apps without requiring sign-out or restart. [Taskbar] Fixed an issue for Insiders using the new smaller taskbar option, where the system tray might get cut off or pushed off screen. [Settings] - Also available in Beta Improved reliability of Settings > Apps > Startup. [Virtualization] - Also available in Beta This update addresses an issue that could result in bugchecks citing HYPERVISOR_ERROR (0x20001) and KMODE_EXCEPTION_NOT_HANDLED (0x1E) errors after installing the latest flights on some devices during system restarts, virtual machine operations, or while running some gaming applications. You can find the official changelog for the Experimental build here and for the Beta build here.
    • I've always preferred this possibility. There is something that feels good about the idea that all matter in the universe will eventually come back together and maybe even result in another big bang. The idea that the universe would fizzle out over the eons and forever drift apart is a little depressing. I realize it is not logical to let a basic human desire for life to have a grand everlasting meaning change the way I feel about a scientific theory, but I am human, so that is how I feel :-).
    • Windoze 11 could finally go to hell, instead of making me savor yet another error I've never had. "Bad Pool Caller" or whatever TF cryptic crap0la message it is. Adding salt to injury, it says something along these lines (on the blank black screen after it hard stops): "Your windoze needs to restart. You can restart." NO WAY SHERLOCK. The PEECEE, look, it's *blocked*, I can do jack sh1t with it as it is and you say that it needs to restart? Further, that I can restart? What am I supposed to do, take a herbal bath? Sudo a sandwich? Timewaster pile of useless slop and errors, coded by monkeys and force-fed on us by a pedo-founded corporation, that's all there is to it. Now, let's have a fun weekend trying to handle the error, which after a quick internet check can basically be due to EVERYTHING, from memory faults to drivers to motherboard issues. Thanks M$.
    • Zen Browser 1.21.3b by Razvan Serea Zen Browser is a privacy-focused, open-source web browser built on Mozilla Firefox, offering users a secure and customizable browsing experience. It emphasizes privacy by blocking trackers, ads, and ensuring your data isn't collected. With Zen Mods, users can enhance their browser experience with various customization options, including features like split views and vertical tabs. The browser is designed for efficiency, providing fast browsing speeds and a lightweight interface. Zen Browser prioritizes user control over the browsing experience, offering a minimal yet powerful alternative to traditional web browsers while keeping your online activity private. Zen Browser’s DRM limitation Zen Browser currently lacks support for DRM-protected content, meaning streaming services like Netflix and HBO Max are inaccessible. This is due to the absence of a Widevine license, which requires significant costs and is financially unfeasible for the developer. Additionally, applying for this license would require Zen to be part of a larger company, similar to Mozilla or Brave. Therefore, DRM-protected media won't be supported in Zen Browser for the foreseeable future. Zen Browser offers features that improve user experience, privacy, and customization: Privacy-Focused: Blocks trackers and minimizes data collection. Automatic Updates: Keeps the browser updated with security patches. Zen Mods: Customizable themes and layouts. Workspaces: Organize tabs into different workspaces. Compact Mode: Maximizes screen space by minimizing UI elements. Zen Glance: Quick website previews. Split Views: View multiple tabs in the same window. Sidebar: Access bookmarks and tools quickly. Vertical Tabs: Manage tabs vertically. Container Tabs: Separate browsing sessions. Fast Profile Switcher: Switch between profiles easily. Tab Folders: Organize tabs into folders. Customizable UI: Personalize browser interface. Security Features: Inherits Firefox’s robust security. Fast Performance: Lightweight and optimized for speed. Zen Mods Customization: Deep customization with mods. Quick Access: Easy access to favorite websites. Open Source: Built on Mozilla Firefox with community collaboration. Community-Driven: Active development and feedback from users. GitHub Repository: Contribute and review the source code. Zen Browser 1.21.3b changelog: New Features Updated to Firefox 152.0.1 Fixes Fixed transparency not working after updating to 1.21.2b (#14259) Fixed frequent crashes affecting users with Intel Raptor Lake processors Fixed an issue on macOS where choosing a PDF option, such as "Save as PDF", from the system print dialog would send the job to your printer instead of saving a file. Other minor bug fixes and improvements. Download: Zen Browser | 90.2 MB (Open Source) Download: Zen Browser ARM64 | Other Operating Systems View: Zen Browser Home Page | Screenshots 1 | 2 | Reddit Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Get 1-year and $60 of Sam's Club value for just $15 with Auto-renew by Steven Parker Become a Sam's Club Member Now! Shop Premium-Quality Products and Enjoy Incredible Perks, and Savings. Today's highlighted deal comes via our Gift Cards section of the Neowin Deals store, where for only a limited time, you can save 75% off a Sam's Club 1 Year Membership with Auto-Renew. Sam’s Club is a membership warehouse club, a limited-item business model that offers members quality products at an exceptional value unmatched by traditional retail. From groceries and kitchen supplies to electronics and furniture, Sam's Club has great deals on the items you want! By redeeming and signing up as a member, you'll be paying just $20 for a 1 year Sam's Club membership (normally $50.) You'll receive a complimentary household card for more savings from already low-priced items. Sign up now and save money on all your food and decor. Find great deals on groceries, kitchen supplies, electronic, furniture & more Get discounts on hotels, rental car, live events, attractions, movies, & more Save up to 60% on hotel accommodations around the world Get a complimentary household card for more savings from already low-priced items Although it was published quite some time ago, Sam's Club members can enjoy discounts like this. Important Details For a physical membership card after online membership registration, present your phone number or email along with a valid ID at Sam’s Club Membership Services in any US Sam's Club location to have your membership card printed. This membership offer is only available to new Sam's Club members in the USA. It is not valid for membership renewals, for those with a current membership, or those who were Sam’s Club members less than 6 months prior to the current date. To check your renewal date, please check your billing statement or your online account, or chat with an associate. Promotion code is non-transferable Offer valid for new Sam’s Club members only; not valid for membership renewals, for those with a current membership, or those who were Sam’s Club members less than 6 months prior to the current date. Auto Renew: By accepting this offer, you authorize annual recurring charges to any card on file for your Sam's Club membership fee(s) plus any applicable taxes at then-current rate every year until you cancel. Current rates, which may change, are $50 for Club level and $110 for Plus level. Visit SamsClub.com or a club or call 1-888-746-7726 for full terms or to cancel auto-renewal. Valid at over 597 U.S. Sam’s Club locations. Find a location near you. Redemption deadline: redeem your code within 30 days of purchase Access options: desktop & mobile Membership MUST be activated within 30 days Membership expires 1 YEAR from the date the Sam's Club membership is activated Limit 1 per person, may buy 1 additional as gift This Sam's Club 1 Year Membership normally costs $60, but can now be yours for just $15, for a limited time, that's a saving of $45 (70%) off! For specifications, and terms, please click the link below. Get 1-year of Sam's Club with Auto-renew for just $15 (was $60) This deal is only available to U.S. residents. Support queries If you have queries or need support for any of the Neowin Deals, please use the contact form here. Neowin Deals are managed and sold by StackCommerce who represent Neowin on an affiliate basis. Why we post these deals We post these because we earn commission on each sale so as not to rely solely on advertising, which many of our readers block. It all helps toward paying staff reporters, servers and hosting costs. So for those that keep moaning and complaining, be thankful we're still online for you to even do that. Other ways to support Neowin Whitelist Neowin by not blocking our ads Create a free member account to see fewer ads Make a donation to support our day to day running costs Subscribe to Neowin - for $14 a year, or $28 a year for an ad-free experience Disclosure: Neowin benefits from revenue of each sale made through our branded deals site powered by StackCommerce.
  • Recent Achievements

    • Collaborator
      ryansurfer98 went up a rank
      Collaborator
    • Week One Done
      Eurosoft10 earned a badge
      Week One Done
    • One Month Later
      Eurosoft10 earned a badge
      One Month Later
    • One Year In
      Skeet Campbell earned a badge
      One Year In
    • One Month Later
      Sharbel earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      578
    2. 2
      +Edouard
      190
    3. 3
      Michael Scrip
      77
    4. 4
      PsYcHoKiLLa
      76
    5. 5
      Steven P.
      73
  • Tell a friend

    Love Neowin? Tell a friend!