I want a way where it is possible to identify individual entries to SharePoint Custom list easily. This will require a unique ID for each entry in the SharePoint List.
Apr 11, 2020 Python random.seed to initialize the pseudo-random number generator. Generate a same random number using seed.Use randrange, choice, sample and shuffle method with seed method. Seed value is very important to generate a strong secret encryption key. Generate 16-digit unique code (like product serial) Ask Question Asked 3 years ago. A product serial key. Anyway, I think this code is not satisfied with the third condition (no duplication). Generate random and unique array of int values for a given size. Jun 24, 2018 Conceptually, the basic idea is to encrypt a key piece of your program in a way that requires a unique piece of data available from only one computer, such as a particular computer’s serial number, to decrypt. The question is, how to do it in a wa.
One easy way to do it is just to use the ID field that is a default field in a SharePoint List which is a basically the sequence number based on the order of creation in a list. But this unique ID is not be easily relatable, as it is difficult for someone to remember this unique ID especially if there are a lot of entries in the list.
I decided to create a unique id based on the sequence of the entry created per day prefixed by the date. (e.g the fist entry created on 21st Jan 2017 will be 201701210001 and the first entry created on 22nd Jan 2017 will be 201701220001)
Have a look at the uuid module (Python 2.5+). A quick example: import uuid uid = uuid.uuid4 uid.hex 'df008b2e24f947b1b873c94d8a3f2201' Note that the OP asked for a 16-character alphanumeric string, but UUID4 strings are 32 characters long. You should not truncate this string, instead, use the complete 32 characters. Most pythonic way to generate a URL safe unique key or token is to use secrets module. Use secrets.tokenurlsafe it will return a secure random URL-safe text string. The secrets module uses synchronization methods to ensure that no two processes can obtain the same data at the same time.
Create two SharePoint Custom Lists(shown below are the necessary columns)
This is the main list where the unique ticket number is shown. You can customise it by add any additional fields you like.
Title (Multi Line Text): This is the field where you key in the title of your request
DateCreated(Calculated (calculation based on other columns)): This is to format the default Created field which have date and time format to YYYYMMDD format
Counter (Number): This is to store the counter which is the sequence that the ticket is created of the day. Set this field as hidden as it is not to be availalble for input (Go to advanced settings->Allow Managment of Content Type Yes->Go to the Item Content type and set the Counter field as hidden)
CalculatedCounter (Calculated (calculation based on other columns)): This is to enhanced the counter with prefix 0s(zeros) in front so as to create a possibly of more numbers(eg. first ticket of the day will have counter 0001 so the last ticket of the day can run to 9999). You can also add some more prefix or suffix on your preference to differentiate the tickets (e.g. you can add INC in front to create a ticket number for incident ticket)
Ticket Number (Calculated (calculation based on other columns)): This is to store the unique ticket ID by combining the DateCreated and CalculatedCounter
You can also add other fields that you want for the type of ticketing system you are created (e.g. helpdesk ticket, incident ticket)
For reference purpose to create the unique ID, this list will only have a single entry at all times
Fields | Type | Explanation |
---|---|---|
Title | Single Line of Text | This is a default column that we will use to store a date in YYYYMMDD format for reference so if a ticket is created on the next available day, it will help to reset the number counter back to 1. If a new ticket is created on the same day, it will increment the number counter by 1 |
Counter | Number | This is the counter which is the sequence number of a ticket created per day |
Create the first and only entry in the ITRS SharePoint List. You just need to add a first entry by keying in something to the title field of the first record(Don’t need to worry about what is keyed in as the SharePoint Workflow will work around it later). Do not key in anything in the counter field.
Now its time to create the workflow.Go to Library->Workflow Settings dropdown arrow->Create a Workflow in SharePoint Designer
Name your Workflow and set Platform Type to ‘SharePoint 2010 Workflow’ .Note I used a SharePoint 2010 Workflow for this despite using SharePoint 2013 as the 2010 Workflow is good enough to get this done. So you can do this in both SharePoint 2010 and SharePoint 2013.
Check for the calculated field DateCreated against the title in ITRS list(note we look for the entry we want in ITRS by finding the entry with ID 1, as there will only be one entry in ITRS permanently, the ID will always be 1. Do take note to never delete the entry in ITRS)
If they don’t tally, that means it is the first ticket created on that day and thus counter will be 1
Update the ITRS entry by changing the title to the value in DateCreated and counter in ITRS to 1
If they tally, that means the counter in Ticket System will need to increment by one. So create a variable(calc) to store the incremented number
Write the variable(calc) value to the counter in the current item of Ticket System
Set the workflow to run automatically when an item is created
The unique ticket number will then be created as it is a calculated value based on the DateCreated field and CalculatedCounter field(which in turn is created from Counter field)
PEP: | 289 |
---|---|
Title: | Generator Expressions |
Author: | python at rcn.com (Raymond Hettinger) |
Status: | Final |
Type: | Standards Track |
Created: | 30-Jan-2002 |
Python-Version: | 2.4 |
Post-History: | 22-Oct-2003 |
Contents
This PEP introduces generator expressions as a high performance,memory efficient generalization of list comprehensions [1] andgenerators [2].
Experience with list comprehensions has shown their widespreadutility throughout Python. However, many of the use cases donot need to have a full list created in memory. Instead, theyonly need to iterate over the elements one at a time.
For instance, the following summation code will build a full list ofsquares in memory, iterate over those values, and, when the referenceis no longer needed, delete the list:
Memory is conserved by using a generator expression instead:
Similar benefits are conferred on constructors for container objects:
Generator expressions are especially useful with functions like sum(),min(), and max() that reduce an iterable input to a single value:
Generator expressions also address some examples of functionals codedwith lambda:
These simplify to:
List comprehensions greatly reduced the need for filter() and map().Likewise, generator expressions are expected to minimize the needfor itertools.ifilter() and itertools.imap(). In contrast, theutility of other itertools will be enhanced by generator expressions:
Having a syntax similar to list comprehensions also makes it easy toconvert existing code into a generator expression when scaling upapplication.
Early timings showed that generators had a significant performanceadvantage over list comprehensions. However, the latter were highlyoptimized for Py2.4 and now the performance is roughly comparablefor small to mid-sized data sets. As the data volumes grow larger,generator expressions tend to perform better because they do notexhaust cache memory and they allow Python to re-use objects betweeniterations.
(None of this is exact enough in the eye of a reader from Mars, but Ihope the examples convey the intention well enough for a discussion inc.l.py. The Python Reference Manual should contain a 100% exactsemantic and syntactic specification.)
The semantics of a generator expression are equivalent to creatingan anonymous generator function and calling it. For example:
is equivalent to:
Only the outermost for-expression is evaluated immediately, the otherexpressions are deferred until the generator is run:
is equivalent to:
The syntax requires that a generator expression always needs to bedirectly inside a set of parentheses and cannot have a comma oneither side. With reference to the file Grammar/Grammar in CVS,two rules change:
The rule:
changes to:
where testlist_gexp is almost the same as listmaker, but onlyallows a single test after 'for' .. 'in':
Rocksmith 2014 edition key generator. Our key generator will provide you with unique and of course valid cd keys, which will let you activate Rocksmith 2014 copy without any problems. We can give you a 100% guarantee that serial key which you will generate from our Rocksmith 2014 key generator.
The rule for arglist needs similar changes.
This means that you can write:
but you would have to write:
and also:
i.e. if a function call has a single positional argument, it can bea generator expression without extra parentheses, but in all othercases you have to parenthesize it.
The exact details were checked in to Grammar/Grammar version 1.49.
The loop variable (if it is a simple variable or a tuple of simplevariables) is not exposed to the surrounding function. Thisfacilitates the implementation and makes typical use cases morereliable. In some future version of Python, list comprehensionswill also hide the induction variable from the surrounding code(and, in Py2.4, warnings will be issued for code accessing theinduction variable).
For example:
List comprehensions will remain unchanged. For example:
Unfortunately, there is currently a slight syntactic difference.The expression:
is legal, meaning:
But generator expressions will not allow the former version:
is illegal.
The former list comprehension syntax will become illegal in Python3.0, and should be deprecated in Python 2.4 and beyond.
List comprehensions also 'leak' their loop variable into thesurrounding scope. This will also change in Python 3.0, so thatthe semantic definition of a list comprehension in Python 3.0 willbe equivalent to list(<generator expression>). Python 2.4 andbeyond should issue a deprecation warning if a list comprehension'sloop variable has the same name as a variable used in theimmediately surrounding scope.
After much discussion, it was decided that the first (outermost)for-expression should be evaluated immediately and that the remainingexpressions be evaluated when the generator is executed.
Asked to summarize the reasoning for binding the first expression,Guido offered [5]:
Various use cases were proposed for binding all free variables whenthe generator is defined. And some proponents felt that the resultingexpressions would be easier to understand and debug if bound immediately.
However, Python takes a late binding approach to lambda expressions andhas no precedent for automatic, early binding. It was felt thatintroducing a new paradigm would unnecessarily introduce complexity.
After exploring many possibilities, a consensus emerged that bindingissues were hard to understand and that users should be stronglyencouraged to use generator expressions inside functions that consumetheir arguments immediately. For more complex applications, fullgenerator definitions are always superior in terms of being obviousabout scope, lifetime, and binding [6].
The utility of generator expressions is greatly enhanced when combinedwith reduction functions like sum(), min(), and max(). The heapqmodule in Python 2.4 includes two new reduction functions: nlargest()and nsmallest(). Both work well with generator expressions and keepno more than n items in memory at one time.
[1] | PEP 202 List Comprehensionshttp://www.python.org/dev/peps/pep-0202/ |
[2] | PEP 255 Simple Generatorshttp://www.python.org/dev/peps/pep-0255/ |
[3] | Peter Norvig's Accumulation Display Proposalhttp://www.norvig.com/pyacc.html |
[4] | Jeff Epler had worked up a patch demonstratingthe previously proposed bracket and yield syntaxhttps://bugs.python.org/issue795947 |
[5] | (1, 2) Discussion over the relative merits of early versus late bindinghttps://mail.python.org/pipermail/python-dev/2004-April/044555.html |
[6] | (1, 2) Patch discussion and alternative patches on Source Forgehttps://bugs.python.org/issue872326 |
This document has been placed in the public domain.
Source: https://github.com/python/peps/blob/master/pep-0289.txt